SecurityTokenService.GetScope(ClaimsPrincipal, RequestSecurityToken) メソッド

定義

指定したリクエスト (RST) と関連付けられている証明書利用者 (RP) に関する情報を含む Scope オブジェクトを取得します。 このメソッドは、SecurityTokenService クラスの実装でオーバーライドする必要があります。

protected:
 abstract System::IdentityModel::Scope ^ GetScope(System::Security::Claims::ClaimsPrincipal ^ principal, System::IdentityModel::Protocols::WSTrust::RequestSecurityToken ^ request);
protected abstract System.IdentityModel.Scope GetScope (System.Security.Claims.ClaimsPrincipal principal, System.IdentityModel.Protocols.WSTrust.RequestSecurityToken request);
abstract member GetScope : System.Security.Claims.ClaimsPrincipal * System.IdentityModel.Protocols.WSTrust.RequestSecurityToken -> System.IdentityModel.Scope
Protected MustOverride Function GetScope (principal As ClaimsPrincipal, request As RequestSecurityToken) As Scope

パラメーター

principal
ClaimsPrincipal

要求を行っているクライアントを表す ClaimsPrincipal

request
RequestSecurityToken

受信した要求 (RST) を表す RequestSecurityToken

戻り値

要求に関連付けられている RP 情報をカプセル化する Scope

このトピックで使用するコード例は、サンプルから取得したものです Custom Token 。 このサンプルでは、Simple Web Tokens (SWT) の処理を可能にするカスタム クラスを提供し、SWT トークンを提供できるパッシブ STS の実装が含まれています。 アクティブな STS を実装する方法の例については、サンプルを Federation Metadata 参照してください。 WIF で使用できるこれらのサンプルとその他のサンプルの詳細と、それらをダウンロードする場所については、「 WIF コード サンプル インデックス」を参照してください。

GetScope メソッドを実装する方法を次のコード例に示します。 この実装では、RP が STS によって認識されていることを確認し、要求内のアドレスを ReplyTo 検証し、それに応じて プロパティを設定 Scope.ReplyToAddress し、ファイルにハードコーディングされた証明書に基づいて RP で使用する署名と暗号化の資格情報を設定します。

// Certificate Constants
private const string SIGNING_CERTIFICATE_NAME = "CN=localhost";
private const string ENCRYPTING_CERTIFICATE_NAME = "CN=localhost";

private SigningCredentials _signingCreds;
private EncryptingCredentials _encryptingCreds;
// Used for validating applies to address, set to URI used in RP app of application, could also have been done via config
private string _addressExpected = "http://localhost:19851/";
/// <summary>
/// This method returns the configuration for the token issuance request. The configuration
/// is represented by the Scope class. In our case, we are only capable of issuing a token to a
/// single RP identity represented by the _encryptingCreds field.
/// </summary>
/// <param name="principal">The caller's principal</param>
/// <param name="request">The incoming RST</param>
/// <returns></returns>
protected override Scope GetScope(ClaimsPrincipal principal, RequestSecurityToken request)
{
    // Validate the AppliesTo address
    ValidateAppliesTo( request.AppliesTo );

    // Create the scope using the request AppliesTo address and the RP identity
    Scope scope = new Scope( request.AppliesTo.Uri.AbsoluteUri, _signingCreds );

    if (Uri.IsWellFormedUriString(request.ReplyTo, UriKind.Absolute))
    {
        if (request.AppliesTo.Uri.Host != new Uri(request.ReplyTo).Host)
            scope.ReplyToAddress = request.AppliesTo.Uri.AbsoluteUri;
        else
            scope.ReplyToAddress = request.ReplyTo;
    }
    else
    {
        Uri resultUri = null;
        if (Uri.TryCreate(request.AppliesTo.Uri, request.ReplyTo, out resultUri))
            scope.ReplyToAddress = resultUri.AbsoluteUri;
        else
            scope.ReplyToAddress = request.AppliesTo.Uri.ToString() ;
    }

    // Note: In this sample app only a single RP identity is shown, which is localhost, and the certificate of that RP is 
    // populated as _encryptingCreds
    // If you have multiple RPs for the STS you would select the certificate that is specific to 
    // the RP that requests the token and then use that for _encryptingCreds
    scope.EncryptingCredentials = _encryptingCreds;

    return scope;
}
/// <summary>
/// Validates the appliesTo and throws an exception if the appliesTo is null or appliesTo contains some unexpected address.
/// </summary>
/// <param name="appliesTo">The AppliesTo parameter in the request that came in (RST)</param>
/// <returns></returns>
void ValidateAppliesTo(EndpointReference appliesTo)
{
    if (appliesTo == null)
    {
        throw new InvalidRequestException("The appliesTo is null.");
    }

    if (!appliesTo.Uri.Equals(new Uri(_addressExpected)))
    {
        throw new InvalidRequestException(String.Format("The relying party address is not valid. Expected value is {0}, the actual value is {1}.", _addressExpected, appliesTo.Uri.AbsoluteUri));
    }
}

注釈

メソッドは GetScope 、 メソッドの後 ValidateRequest にトークン発行パイプラインから呼び出され、受信要求用に Scope 構成された オブジェクトを返す必要があります。 (トークン発行パイプラインは メソッドに Issue 実装されています)。オブジェクトは Scope 、セキュリティ トークン要求 (RST) に関連付けられている RP に関する情報をカプセル化します。 これには、RP で使用される暗号化と署名の資格情報、および応答で発行されたトークンや対称キーを暗号化するかどうかに関する情報が含まれます。 メソッドで GetScope 実行される一般的なタスクは次のとおりです。

  • トークンが意図されている RP が認識された RP であるかどうかを判断します。 これを実現する方法は、実装によって異なります。 目的の RP がこの STS に対して有効な RP でない場合、メソッドは をスローする InvalidRequestException必要があります。

  • 応答 (RSTR) で使用する署名資格情報を決定し、それに応じて プロパティを設定します SigningCredentials

  • 応答や含まれている対称キーを暗号化する必要があるかどうか、および暗号化に使用する資格情報を決定します。 それに応じて、 TokenEncryptionRequiredSymmetricKeyEncryptionRequired、および の各プロパティを EncryptingCredentials 設定します。

    重要

    既定では、 TokenEncryptionRequired プロパティと SymmetricKeyEncryptionRequired プロパティは、STS がセキュリティで保護されていないトークンを発行しないように設定 true されています。 運用環境では、これらのプロパティを に false 設定しないでください。

  • 応答を返すアドレスを決定します。 必要に AppliesToAddress 応じて、 または ReplyToAddress プロパティを設定します。

注意 (実装者)

このメソッドは、SecurityTokenService クラスの実装でオーバーライドする必要があります。

適用対象

こちらもご覧ください