RequestSecurityToken 類別

定義

表示 wst:RequestSecurityToken 項目 (RST),這用來要求安全性權杖。

public ref class RequestSecurityToken : System::IdentityModel::Protocols::WSTrust::WSTrustMessage
public class RequestSecurityToken : System.IdentityModel.Protocols.WSTrust.WSTrustMessage
type RequestSecurityToken = class
    inherit WSTrustMessage
Public Class RequestSecurityToken
Inherits WSTrustMessage
繼承
RequestSecurityToken

範例

本主題中使用的程式代碼範例取自 Custom Token 範例。 此範例提供自定義類別,可讓您處理簡單的 Web 令牌 (SWT) ,並包含能夠提供 SWT 令牌的被動 STS 實作。 STS 是由衍生自 SecurityTokenService的類別實作。 從其令牌發行管線呼叫之 類別的許多 SecurityTokenService 方法,會採用 RequestSecurityToken 對象作為其參數。 如需此範例和其他可供 WIF 使用之範例以及下載位置的相關信息,請參閱 WIF 程式代碼範例索引

下列程式碼範例示範 SecurityTokenService.GetScope 方法的實作。 方法會採用 RequestSecurityToken 做為其其中一個參數,而這個參數的屬性是用來設定 方法所傳回之對象的屬性 Scope

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

備註

wst:RequestSecurityToken 元素 (訊息) 包含用來向安全性令牌服務要求安全性令牌的參數和屬性, (STS) 。 訊息 (或元素) 縮寫為 RST。 類別 RequestSecurityToken 包含代表 RST 元素的屬性。 RST 可以形成對應於 WS-Trust 所定義之任何要求系結的要求;例如,發行系結、更新系結、驗證系結或 Cancel 系結。 類別中的 RequestSecurityToken 許多屬性都對應至只有這些系結所定義之特定要求類型中的專案。 根據特定 RequestSecurityToken 物件所代表的要求類型,或它所代表之特定要求中的參數,物件的某些屬性可能是 null

STS 會在包含 wst:RequestSecurityTokenResponse 元素的訊息中傳回要求的回應, (RSTR) 。 這個訊息是由 RequestSecurityTokenResponse 類別表示。

如需此類別代表項目的詳細資訊,請參閱適用於您案例的 WS-Trust 規格:WS-Trust February 2005WS-Trust 1.3WS-Trust 1.4

建構函式

RequestSecurityToken()

初始化 RequestSecurityToken 類別的新執行個體。

RequestSecurityToken(String)

使用指定的要求類型,初始化 RequestSecurityToken 類別的新執行個體。

RequestSecurityToken(String, String)

使用指定的要求類型,初始化 RequestSecurityToken 類別的新執行個體。

屬性

ActAs

取得或設定要求者嘗試扮演之識別的安全性權杖。

AdditionalContext

取得或設定要求的其他內容資訊。

AllowPostdating

取得或設定 wst:AllowPostdating 項目的內容。

(繼承來源 WSTrustMessage)
AppliesTo

取得或設定 wsp:AppliesTo 項目的內容。

(繼承來源 WSTrustMessage)
AuthenticationType

取得或設定 wst:AuthenticationType 項目的內容。

(繼承來源 WSTrustMessage)
BinaryExchange

取得或設定 wst:BinaryExchange 項目的內容。

(繼承來源 WSTrustMessage)
CancelTarget

取得或設定要在 WS-Trust 取消要求中取消的權杖。

CanonicalizationAlgorithm

取得或設定 wst:CanonicalizationAlgorithm 項目的內容。

(繼承來源 WSTrustMessage)
Claims

取得用戶端 (要求者) 要求的宣告類型。

ComputedKeyAlgorithm

取得 URI,表示計算的金鑰用於所發出權杖時使用的所需演算法。

Context

取得或設定 RST 或 RSTR 上之 Context 屬性的內容。

(繼承來源 WSTrustMessage)
Delegatable

取得或設定值,指定發出的權杖是否應該標示為可委派。

DelegateTo

取得或設定發出的權杖應該委派到的識別。

Encryption

取得或設定加密時要使用之權杖和金鑰的資訊。

EncryptionAlgorithm

取得或設定 wst:EncryptionAlgorithm 項目的內容。

(繼承來源 WSTrustMessage)
EncryptWith

取得或設定 wst:EncryptWith 項目的內容。

(繼承來源 WSTrustMessage)
Entropy

取得或設定 wst:Entropy 項目的內容。

(繼承來源 WSTrustMessage)
Forwardable

取得或設定值,指定發出的權杖是否應該標示為可轉送。

Issuer

取得或設定 wst:OnBehalfOf 權杖的簽發者。

KeySizeInBits

取得或設定在 RequestSecurityToken (RST) 訊息內部的 wst:KeySize 項目的內容。

(繼承來源 WSTrustMessage)
KeyType

取得或設定在 RequestSecurityToken (RST) 訊息內部的 wst:KeyType 項目的內容。

(繼承來源 WSTrustMessage)
KeyWrapAlgorithm

取得或設定 wst:KeyWrapAlgorithm 項目的內容。

(繼承來源 WSTrustMessage)
Lifetime

取得或設定在 RequestSecurityToken (RST) 訊息內部的 wst:Lifetime 項目的內容。

(繼承來源 WSTrustMessage)
OnBehalfOf

取得或設定識別的權杖,代表此識別提出要求。

Participants

取得或設定獲授權使用所發出權杖的參與者。

ProofEncryption

取得或設定用來加密證明權杖的權杖。

Properties

取得要擴充物件的屬性封包。

(繼承來源 OpenObject)
Renewing

取得或設定 WS-Trust 更新要求的更新語意。

RenewTarget

取得或設定要在 WS-Trust 更新要求中更新的權杖。

ReplyTo

取得或設定要用來回覆信賴憑證者的位址。

(繼承來源 WSTrustMessage)
RequestType

取得或設定 wst:RequestType 項目。

(繼承來源 WSTrustMessage)
SecondaryParameters

取得或設定要求者不是建立者的參數。

SignatureAlgorithm

取得或設定 wst:SignatureAlgorithm 項目的內容。

(繼承來源 WSTrustMessage)
SignWith

取得或設定 wst:SignWith 項目的內容。

(繼承來源 WSTrustMessage)
TokenType

取得或設定 wst:TokenType 項目的內容。

(繼承來源 WSTrustMessage)
UseKey

取得或設定 wst:UseKey 項目的內容。

(繼承來源 WSTrustMessage)
ValidateTarget

取得或設定要在 WS-Trust 驗證要求中驗證的權杖。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱