SecurityTokenProvider.GetTokenCore Method (TimeSpan)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets a security token.

Namespace:   System.IdentityModel.Selectors
Assembly:  System.IdentityModel (in System.IdentityModel.dll)

protected abstract SecurityToken GetTokenCore(
	TimeSpan timeout
)

Parameters

timeout
Type: System.TimeSpan

A TimeSpan that specifies the timeout value for the message that gets the security token.

Return Value

Type: System.IdentityModel.Tokens.SecurityToken

The SecurityToken that represents the security token to get.

When the GetTokenCore method is overridden and the security token passed into the token parameter cannot be obtained, throw the SecurityTokenException exception.

The GetToken method is called by the ClientCredentials class when a client sends a SOAP message and a security token is required.

The GetToken method calls the GetTokenCore method.

protected override SecurityToken GetTokenCore(TimeSpan timeout)
{
    // Create a SamlSecurityToken from the provided assertion
    SamlSecurityToken samlToken = new SamlSecurityToken(assertion);

    // Create a SecurityTokenSerializer that will be used to serialize the SamlSecurityToken
    WSSecurityTokenSerializer ser = new WSSecurityTokenSerializer();

    // Create a memory stream to write the serialized token into
    // Use an initial size of 64Kb
    MemoryStream s = new MemoryStream(UInt16.MaxValue);

    // Create an XmlWriter over the stream
    XmlWriter xw = XmlWriter.Create(s);

    // Write the SamlSecurityToken into the stream
    ser.WriteToken(xw, samlToken);

    // Seek back to the beginning of the stream
    s.Seek(0, SeekOrigin.Begin);

    // Load the serialized token into a DOM
    XmlDocument dom = new XmlDocument();
    dom.Load(s);

    // Create a KeyIdentifierClause for the SamlSecurityToken
    SamlAssertionKeyIdentifierClause samlKeyIdentifierClause = samlToken.CreateKeyIdentifierClause<SamlAssertionKeyIdentifierClause>();

    // Return a GenericXmlToken from the XML for the SamlSecurityToken, the proof token, the valid from 
    // and valid until times from the assertion and the key identifier clause created above            
    return new GenericXmlSecurityToken(dom.DocumentElement, proofToken, assertion.Conditions.NotBefore, assertion.Conditions.NotOnOrAfter, samlKeyIdentifierClause, samlKeyIdentifierClause, null);
}

.NET Framework
Available since 3.0
Return to top
Show: