Share via


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 샘플입니다. 이 샘플에서는 간단한 웹 토큰 (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 없는 경우 메서드가 throw 해야는 InvalidRequestException합니다.

  • 응답 (RSTR)에서 사용 되 고 설정 하는 서명 자격 증명을 확인 합니다 SigningCredentials 속성 적절 하 게 합니다.

  • 응답 및/또는 포함 된 모든 대칭 키를 암호화 해야 하는지 여부 및 암호화에 사용할 자격 증명을 확인 합니다. 설정 된 TokenEncryptionRequired, SymmetricKeyEncryptionRequired, 및 EncryptingCredentials 속성 적절 하 게 합니다.

    중요

    기본적으로 TokenEncryptionRequiredSymmetricKeyEncryptionRequired 속성이 설정 되어 true STS는 안전 하지 않은 토큰을 발급 하지 못하도록 합니다. 이러한 속성을으로 설정 하지는 것이 좋습니다. false 프로덕션 환경에서.

  • 응답은 반환할 주소를 확인 합니다. 설정 된 AppliesToAddress 또는 ReplyToAddress 속성 적절 하 게 합니다.

구현자 참고

SecurityTokenService 클래스의 구현에서 이 메서드를 재정의해야 합니다.

적용 대상

추가 정보