SecurityTokenHandler.CreateToken(SecurityTokenDescriptor) Método

Definição

Quando substituído em uma classe derivada, cria um token de segurança usando o descritor de token especificado.When overridden in a derived class, creates a security token using the specified token descriptor. Este método é chamado por um STS (serviço de token de segurança).This method is called by a security token service (STS).

public:
 virtual System::IdentityModel::Tokens::SecurityToken ^ CreateToken(System::IdentityModel::Tokens::SecurityTokenDescriptor ^ tokenDescriptor);
public virtual System.IdentityModel.Tokens.SecurityToken CreateToken (System.IdentityModel.Tokens.SecurityTokenDescriptor tokenDescriptor);
abstract member CreateToken : System.IdentityModel.Tokens.SecurityTokenDescriptor -> System.IdentityModel.Tokens.SecurityToken
override this.CreateToken : System.IdentityModel.Tokens.SecurityTokenDescriptor -> System.IdentityModel.Tokens.SecurityToken
Public Overridable Function CreateToken (tokenDescriptor As SecurityTokenDescriptor) As SecurityToken

Parâmetros

tokenDescriptor
SecurityTokenDescriptor

O descritor do token de segurança do qual o token deve ser criado.The security token descriptor from which the token is to be created. Propriedades do descritor de token são definidas antes deste método ser chamado.Properties of the token descriptor are set before this method is called.

Retornos

SecurityToken

Um token de segurança que coincide com as propriedades do descritor de token.A security token that matches the properties of the token descriptor.

Exemplos

O código a seguir mostra como substituir o CreateToken método para criar e retornar um token de um descritor de token.The following code shows how to override the CreateToken method to create and return a token from a token descriptor. O código é extraído do Custom Token exemplo.The code is taken from the Custom Token sample. Este exemplo fornece classes personalizadas que permitem o processamento de tokens da Web simples (SWT).This sample provides custom classes that enable processing of Simple Web Tokens (SWT). Para obter informações sobre esse exemplo e outros exemplos disponíveis para o WIF e onde baixá-los, consulte o índice de exemplo de código do WIF.For information about this sample and other samples available for WIF and where to download them, see WIF Code Sample Index.

public override SecurityToken CreateToken(SecurityTokenDescriptor tokenDescriptor)
{
    if (tokenDescriptor == null)
    {
        throw new ArgumentNullException("tokenDescriptor");
    }

    NameValueCollection properties = new NameValueCollection();
    properties.Add(SimpleWebTokenConstants.Id, Guid.NewGuid().ToString());
    properties.Add(SimpleWebTokenConstants.Issuer, tokenDescriptor.TokenIssuerName);
    properties.Add(SimpleWebTokenConstants.Audience, tokenDescriptor.AppliesToAddress);
    properties.Add(SimpleWebTokenConstants.ExpiresOn, SecondsFromSwtBaseTime(tokenDescriptor.Lifetime.Expires));
    properties.Add(SimpleWebTokenConstants.ValidFrom, SecondsFromSwtBaseTime(tokenDescriptor.Lifetime.Created));

    foreach (Claim claim in tokenDescriptor.Subject.Claims)
    {
        properties.Add(claim.Type, claim.Value);
    }

    SimpleWebToken token = new SimpleWebToken(properties);
    return token;
}

Comentários

Por padrão, esse método gera uma NotImplementedException exceção.By default this method throws a NotImplementedException exception.

Chamado a partir de implementações da SecurityTokenService classe.Called from implementations of the SecurityTokenService class.

Aplica-se a