SecurityTokenProvider.GetTokenCore(TimeSpan) Méthode

Définition

Obtient un jeton de sécurité.

C#
protected abstract System.IdentityModel.Tokens.SecurityToken GetTokenCore (TimeSpan timeout);

Paramètres

timeout
TimeSpan

TimeSpan qui spécifie la valeur du délai d'attente pour le message qui obtient le jeton de sécurité.

Retours

SecurityToken qui représente le jeton de sécurité à obtenir.

Exemples

C#
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);
}

Remarques

Lorsque la méthode GetTokenCore est substituée et que le jeton de sécurité passé dans le paramètre de jeton ne peut pas être obtenu, levez l'exception SecurityTokenException.

La méthode GetToken est appelée par la classe ClientCredentials lorsqu'un client envoie un message SOAP et qu'un jeton de sécurité est requis.

La méthode GetToken appelle la méthode GetTokenCore.

S’applique à

Produit Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1