Rediger

Del via


RequestSecurityToken Class

Definition

Represents the wst:RequestSecurityToken element (RST), which is used to request a security token.

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
Inheritance
RequestSecurityToken

Examples

The code example that is used in this topic is taken from the Custom Token sample. 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. The STS is implemented by a class that is derived from SecurityTokenService. Many of the methods of the SecurityTokenService class that are called from its token issuance pipeline take a RequestSecurityToken object as one if their parameters. For information about this sample and other samples available for WIF and about where to download them, see WIF Code Sample Index.

The following code example shows an implementation of the SecurityTokenService.GetScope method. The method takes a RequestSecurityToken as one of its parameters and properties of this parameter are used to set properties on the Scope object that is returned by the method.

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

Remarks

The wst:RequestSecurityToken element (message) contains the parameters and properties used to request a security token from a security token service (STS). The message (or element) is abbreviated as RST. The RequestSecurityToken class contains properties that represent the elements of the RST. An RST can form a request that corresponds to any of the request bindings defined by WS-Trust; for example, the Issuance binding, the Renewal binding, the Validate binding, or the Cancel binding. Many of the properties in the RequestSecurityToken class correspond to elements that are present only in specific kinds of requests as defined by these bindings. Depending on the kind of request a particular RequestSecurityToken object represents or the parameters present in the specific request that it represents, some properties of the object may be null.

The STS returns a response to the request in a message that contains a wst:RequestSecurityTokenResponse element (RSTR). This message is represented by the RequestSecurityTokenResponse class.

For more information about the element that this class represents, see the WS-Trust specification that applies to your scenario: WS-Trust February 2005, WS-Trust 1.3, or WS-Trust 1.4.

Constructors

RequestSecurityToken()

Initializes a new instance of the RequestSecurityToken class.

RequestSecurityToken(String, String)

Initializes a new instance of the RequestSecurityToken class with the specified request type.

RequestSecurityToken(String)

Initializes a new instance of the RequestSecurityToken class with the specified request type.

Properties

ActAs

Gets or sets the security token for the identity that the requestor is attempting to act as.

AdditionalContext

Gets or sets the additional context information for the request.

AllowPostdating

Gets or sets the contents of the wst:AllowPostdating element.

(Inherited from WSTrustMessage)
AppliesTo

Gets or sets the contents of the wsp:AppliesTo element.

(Inherited from WSTrustMessage)
AuthenticationType

Gets or sets the contents of the wst:AuthenticationType element.

(Inherited from WSTrustMessage)
BinaryExchange

Gets or sets the contents of the wst:BinaryExchange element.

(Inherited from WSTrustMessage)
CancelTarget

Gets or sets the token to be canceled in a WS-Trust cancel request.

CanonicalizationAlgorithm

Gets or sets the contents of the wst:CanonicalizationAlgorithm element.

(Inherited from WSTrustMessage)
Claims

Gets the claim types requested by the client (requestor).

ComputedKeyAlgorithm

Gets a URI that represents the desired algorithm to use when computed keys are used for issued tokens.

Context

Gets or sets the contents of the Context attribute on the RST or RSTR.

(Inherited from WSTrustMessage)
Delegatable

Gets or sets a value that specifies if the issued token should be marked as delegatable.

DelegateTo

Gets or sets the identity to which the issued token should be delegated.

Encryption

Gets or sets information on the token and key to use when encrypting.

EncryptionAlgorithm

Gets or sets the contents of the wst:EncryptionAlgorithm element.

(Inherited from WSTrustMessage)
EncryptWith

Gets or sets the contents of the wst:EncryptWith element.

(Inherited from WSTrustMessage)
Entropy

Gets or sets the contents of the wst:Entropy element.

(Inherited from WSTrustMessage)
Forwardable

Gets or sets a value that specifies if the issued token should be marked forwardable.

Issuer

Gets or sets the issuer of the wst:OnBehalfOf token.

KeySizeInBits

Gets or sets the contents of the wst:KeySize element inside a RequestSecurityToken (RST) message.

(Inherited from WSTrustMessage)
KeyType

Gets or sets the contents of the wst:KeyType element inside a RequestSecurityToken (RST) message.

(Inherited from WSTrustMessage)
KeyWrapAlgorithm

Gets or sets the contents of the wst:KeyWrapAlgorithm element.

(Inherited from WSTrustMessage)
Lifetime

Gets or sets the contents of the wst:Lifetime element inside a RequestSecurityToken (RST) message.

(Inherited from WSTrustMessage)
OnBehalfOf

Gets or sets the token for the identity on behalf of which the request is being made.

Participants

Gets or sets the participants that are authorized to use the issued token.

ProofEncryption

Gets or sets the token to be used to encrypt the proof token.

Properties

Gets the properties bag to extend the object.

(Inherited from OpenObject)
Renewing

Gets or sets the renew semantics for a WS-Trust renew request.

RenewTarget

Gets or sets the token to be renewed in a WS-Trust renew request.

ReplyTo

Gets or sets the address to be used for replying to the Relying Party.

(Inherited from WSTrustMessage)
RequestType

Gets or sets the wst:RequestType element.

(Inherited from WSTrustMessage)
SecondaryParameters

Gets or sets parameters for which the requestor is not the originator.

SignatureAlgorithm

Gets or sets the contents of the wst:SignatureAlgorithm element.

(Inherited from WSTrustMessage)
SignWith

Gets or sets the contents of the wst:SignWith element.

(Inherited from WSTrustMessage)
TokenType

Gets or sets the contents of the wst:TokenType element.

(Inherited from WSTrustMessage)
UseKey

Gets or sets the contents of the wst:UseKey element.

(Inherited from WSTrustMessage)
ValidateTarget

Gets or sets the token to be validated in a WS-Trust validate request.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also