RequestSecurityToken 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示用于请求安全令牌的 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
- 继承
示例
本主题中使用的代码示例取自 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 元素(message)包含用于从安全令牌服务(STS)请求安全令牌的参数和属性。 消息(或元素)缩写为 RST。 该 RequestSecurityToken 类包含表示 RST 元素的属性。 RST 可以形成与 WS-Trust 定义的任何请求绑定相对应的请求;例如,颁发绑定、续订绑定、验证绑定或取消绑定。 类中的 RequestSecurityToken 许多属性对应于仅存在于这些绑定定义的特定类型的请求中的元素。 根据特定 RequestSecurityToken 对象所表示的请求类型或它所表示的特定请求中存在的参数,该对象的某些属性可能是 null。
STS 在包含 wst:RequestSecurityTokenResponse 元素(RSTR)的消息中返回对请求的响应。 此消息由 RequestSecurityTokenResponse 类表示。
有关此类表示的元素的详细信息,请参阅适用于你的方案的 WS-Trust 规范: 200WS-Trust 5 年 2 月WS-Trust 1.3 或 WS-Trust 1.4。
构造函数
| 名称 | 说明 |
|---|---|
| RequestSecurityToken() |
初始化 RequestSecurityToken 类的新实例。 |
| RequestSecurityToken(String, String) |
使用指定的请求类型初始化类的新实例 RequestSecurityToken 。 |
| RequestSecurityToken(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,该 URI 表示在计算密钥用于颁发的令牌时要使用的所需算法。 |
| Context |
获取或设置 RST 或 RSTR 上的 Context 属性的内容。 (继承自 WSTrustMessage) |
| Delegatable |
获取或设置一个值,该值指定是否应将颁发的令牌标记为 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) |