共用方式為


SecurityTokenService.GetOutputClaimsIdentity 方法

定義

在衍生類別中覆寫,這個方法會傳回包含在已發行權杖中的輸出主體集合。

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

參數

principal
ClaimsPrincipal

ClaimsPrincipal,表示權杖要求者的身分識別。

request
RequestSecurityToken

RequestSecurityToken,表示安全性權杖要求。 這包括要求訊息,以及其他用戶端的相關資訊,例如授權內容。

scope
Scope

Scope,其中包含與要求相關聯之信賴憑證者的相關資訊。 這是 Scope 方法所傳回的 GetScope(ClaimsPrincipal, RequestSecurityToken) 物件。

傳回

包含將放入已發行安全性權杖之宣告集合的 ClaimsIdentity

範例

本主題中使用的程式代碼範例取自 Custom Token 範例。 此範例提供自定義類別,可讓您處理簡單的 Web 令牌 (SWT) ,並包含能夠提供服務 SWT 令牌的被動 STS 實作。 如需如何實作使用中 STS 的範例,您可以看到 Federation Metadata 範例。 如需這些範例和其他適用於 WIF 之範例的相關信息,以及下載這些範例的位置,請參閱 WIF 程式代碼範例索引。 下列程式代碼示範如何覆寫 GetOutputClaimsIdentity 方法,以傳回 STS 的宣告。 在此範例中,會忽略要求安全性令牌 (RST) 訊息,並根據 STS 驗證的使用者收集宣告。

/// <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;
}

備註

方法 GetOutputClaimsIdentity 是從方法實作 Issue 的令牌發行管線呼叫。 它會根據參數 (參數的要求者、傳入的 RST (principal) 參數) request,以及令牌預定 (scope 參數 (參數的信賴憑證者,傳回ClaimsIdentity包含要包含在所發行安全性令牌中的宣告) 。 此方法中的邏輯主要涉及回答下列問題:

  • 回應中應該包含哪一種宣告類型,其用途為 RP? 一般而言,這會根據每個 RP 決定每個 RP 所需的宣告類型清單,或根據每個要求檢查 Claims 要求的屬性。 不過,判斷回應中包含宣告的邏輯和詳細數據完全取決於您的實作。

  • 應該將哪些宣告值指派給回應中的宣告? 對於識別提供者 (IP-STS) ,這通常表示在要求者的 ClaimsPrincipal (中使用參數) 提供的 principal 一或多個宣告,以存取存放區 (或其他實體) 傳回必要宣告類型的值。 對於同盟提供者 (R-STS) 這通常表示對要求者的傳入宣告執行某種處理,以履行要求;或許會對要求者呈現的某些宣告執行篩選或轉換,同時透過未修改的方式傳遞其他宣告。 當然,如同決定回應中包含哪些宣告時,如何判斷這些宣告值的詳細數據和邏輯取決於您的實作。

給實施者的注意事項

您必須在 SecurityTokenService 類別的實作中覆寫此方法。

適用於

另請參閱