SecurityTokenService.GetOutputClaimsIdentity(ClaimsPrincipal, RequestSecurityToken, Scope) Método
Definição
Quando substituído em uma classe derivada, esse método retorna uma coleção de entidades de saída a serem incluídas no token emitido.When overridden in a derived class, this method returns a collection of output subjects to be included in the issued token.
protected:
abstract System::Security::Claims::ClaimsIdentity ^ GetOutputClaimsIdentity(System::Security::Claims::ClaimsPrincipal ^ principal, System::IdentityModel::Protocols::WSTrust::RequestSecurityToken ^ request, System::IdentityModel::Scope ^ scope);
protected abstract System.Security.Claims.ClaimsIdentity GetOutputClaimsIdentity (System.Security.Claims.ClaimsPrincipal principal, System.IdentityModel.Protocols.WSTrust.RequestSecurityToken request, System.IdentityModel.Scope scope);
abstract member GetOutputClaimsIdentity : System.Security.Claims.ClaimsPrincipal * System.IdentityModel.Protocols.WSTrust.RequestSecurityToken * System.IdentityModel.Scope -> System.Security.Claims.ClaimsIdentity
Protected MustOverride Function GetOutputClaimsIdentity (principal As ClaimsPrincipal, request As RequestSecurityToken, scope As Scope) As ClaimsIdentity
Parâmetros
- principal
- ClaimsPrincipal
Um ClaimsPrincipal que representa a identidade do solicitante do token.A ClaimsPrincipal that represents the identity of the token requestor.
- request
- RequestSecurityToken
Um RequestSecurityToken que representa a solicitação do token de segurança.A RequestSecurityToken that represents the security token request. Isso inclui a mensagem de solicitação, bem como outras informações relacionadas ao cliente, como o contexto de autorização.This includes the request message as well as other client related information such as authorization context.
- scope
- Scope
O Scope que contém informações sobre a terceira parte confiável associada à solicitação.The Scope that contains information about the relying party associated with the request. Este é o objeto Scope que foi retornado pelo método GetScope(ClaimsPrincipal, RequestSecurityToken).This is the Scope object that was returned by the GetScope(ClaimsPrincipal, RequestSecurityToken) method.
Retornos
Um ClaimsIdentity que contém a coleção de declarações que serão colocadas no token de segurança emitido.A ClaimsIdentity that contains the collection of claims that will be placed in the issued security token.
Exemplos
O exemplo de código usado neste tópico é obtido do Custom Token exemplo.The code example that is used in this topic is taken from the Custom Token sample. Este exemplo fornece classes personalizadas que permitem o processamento de tokens da Web simples (SWT) e inclui uma implementação de um STS passivo que é capaz de servir um token SWT.This sample provides custom classes that enable processing of Simple Web Tokens (SWT) and it includes an implementation of a passive STS that is capable of serving an SWT token. Para obter um exemplo de como implementar um STS ativo, você pode ver o Federation Metadata exemplo.For an example of how to implement an active STS, you can see the Federation Metadata sample. Para obter informações sobre esses exemplos e outros exemplos disponíveis para o WIF e sobre onde baixá-los, consulte o índice de exemplo de código do WIF.For information about these samples and other samples available for WIF and about where to download them, see WIF Code Sample Index. O código a seguir mostra como substituir o GetOutputClaimsIdentity método para retornar declarações para seu STS.The following code shows how to override the GetOutputClaimsIdentity method to return claims for your STS. Neste exemplo, a mensagem de RST (solicitação de token de segurança) é ignorada e uma coleção de declarações com base no usuário como autenticado no STS é retornada.In this example, the Request Security Token (RST) message is ignored and a collection of claims based on the user as authenticated at the STS is returned.
/// <summary>
/// This method returns the content of the issued token. The content is represented as a set of
/// IClaimIdentity intances, each instance corresponds to a single issued token. Currently, the Windows Identity Foundation only
/// supports a single token issuance, so the returned collection must always contain only a single instance.
/// </summary>
/// <param name="scope">The scope that was previously returned by GetScope method</param>
/// <param name="principal">The caller's principal</param>
/// <param name="request">The incoming RST, we don't use this in our implementation</param>
/// <returns></returns>
protected override ClaimsIdentity GetOutputClaimsIdentity( ClaimsPrincipal principal, RequestSecurityToken request, Scope scope )
{
//
// Return a default claim set which contains a custom decision claim
// Here you can actually examine the user by looking at the IClaimsPrincipal and
// return the right decision based on that.
//
ClaimsIdentity outgoingIdentity = new ClaimsIdentity();
outgoingIdentity.AddClaims(principal.Claims);
return outgoingIdentity;
}
Comentários
O GetOutputClaimsIdentity método é chamado a partir do pipeline de emissão de token, que é implementado pelo Issue método.The GetOutputClaimsIdentity method is called from the token issuance pipeline, which is implemented by the Issue method. Ele retorna um ClaimsIdentity que contém as declarações a serem incluídas no token de segurança emitido com base no solicitante do token (o principal parâmetro), o RST de entrada (o request parâmetro) e a terceira parte confiável para a qual o token se destina (o scope parâmetro).It returns an ClaimsIdentity that contains the claims to include in the issued security token based on the requestor of the token (the principal parameter), the incoming RST (the request parameter), and the relying party for which the token is intended (the scope parameter). A lógica nesse método se preocupa principalmente com a resposta das seguintes perguntas:The logic in this method is primarily concerned with answering the following questions:
Quais tipos de declaração devem ser incluídos na resposta com base na RP para a qual ele se destina?Which claim types should be included in the response based on the RP for which it is intended? Normalmente, isso é decidido por RP a partir de listas de tipos de declaração necessários para cada RP ou por solicitação examinando a Claims propriedade da solicitação.Typically this is decided on a per-RP basis from lists of claim types required for each RP or on a per-request basis by examining the Claims property of the request. No entanto, a lógica e os detalhes para determinar as declarações a serem incluídas na resposta são completamente atualizados para sua implementação.However, the logic and details for determining the claims to include in the response is completely up to your implementation.
Quais valores de declaração devem ser atribuídos às declarações na resposta?Which claim values should be assigned to the claims in the response? Para um provedor de identidade (IP-STS), isso normalmente significa usar uma ou mais declarações no solicitante ClaimsPrincipal (fornecido pelo
principalparâmetro) para acessar uma loja (ou outra entidade) para retornar valores para os tipos de declaração necessários.For an Identity Provider (IP-STS) this typically means using one or more claims in the requestor's ClaimsPrincipal (provided by theprincipalparameter) to access a store (or other entity) to return values for the required claim types. Para um provedor de Federação (R-STS), isso normalmente significa executar algum tipo de processamento nas declarações de entrada do solicitante para atender à solicitação; Talvez executar filtragem ou transformação em algumas declarações apresentadas pelo solicitante, ao mesmo tempo passando outros por não modificados.For a Federation Provider (R-STS) this typically means performing some kind of processing on the requestor's incoming claims to fulfill the request; perhaps performing filtering or transformation on some claims presented by the requestor, while passing others through unmodified. É claro que, como no caso de decidir quais declarações incluir na resposta, os detalhes e a lógica de como determinar os valores dessas declarações cabem à sua implementação.Of course, as in the case of deciding which claims to include in the response, the details and logic of how to determine the values of these claims is up to your implementation.
Notas aos Implementadores
Você deve substituir esse método em sua implementação da classe SecurityTokenService.You must override this method in your implementation of the SecurityTokenService class.