Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WIF的自定义SecurityTokenHandler_C#_.net_Wif_Sts Securitytokenservice - Fatal编程技术网

C# WIF的自定义SecurityTokenHandler

C# WIF的自定义SecurityTokenHandler,c#,.net,wif,sts-securitytokenservice,C#,.net,Wif,Sts Securitytokenservice,我正在尝试使用Microsoft.IdentityModel(=Windows Identity Foundation)为STS实现自定义的SecurityToken 令牌被序列化为带有签名的简单xml文档(使用X509证书),并且有时(并非总是)加密(取决于目标领域) 到目前为止,它工作得相当好,但我一直在思考哪个应该返回一个securitykeyindifierclause 我的问题是:什么是SecurityKey,securitykeyidentifier,通常是什么,具体是什么是我的sc

我正在尝试使用Microsoft.IdentityModel(=Windows Identity Foundation)为STS实现自定义的
SecurityToken

令牌被序列化为带有签名的简单xml文档(使用X509证书),并且有时(并非总是)加密(取决于目标领域)

到目前为止,它工作得相当好,但我一直在思考哪个应该返回一个
securitykeyindifierclause

我的问题是:什么是
SecurityKey
securitykeyidentifier
,通常是什么,具体是什么是我的sceanrio(rsa签名(并加密)xml令牌)

MSDN中几乎没有任何文档,我也找不到关于这个主题的任何其他帮助

提前谢谢


注:我知道最简单和推荐的方法是使用类似saml的内置令牌格式,但该令牌是由一个传统系统评估的,该系统希望使用一种我不影响的特定格式。

关键标识符与自定义令牌一起使用,以完成一些事情。它们描述令牌,和/或指向其他相关令牌(因为令牌可能只是指针——可能是出于性能等原因)。如果不需要密钥标识符,可以做两件事:

  • 从CanWriteKeyIdentifierClause返回false:

    公共覆盖布尔CanWriteKeyIdentifierClause(SecurityKeyIdentifierClause SecurityKeyIdentifierClause) { 返回false; }

  • 从CreateSecurityTokenReference返回默认(或空)值:

    public override SecurityKeyIdentifierClause CreateSecurityTokenReference(SecurityToken令牌,bool附加) { 返回默认值(SecurityKeyIdentifierClause); }


与此同时,我自己找到了问题的答案:

安全密钥

SecurityKey用于加密操作。这不是承载令牌实现所需要的。因此,您只需在SecurityToken的相应属性中返回一个空列表:

SecurityKeyIdentifier

SecurityKeyIdentifier是SecurityKeyIdentifierClause的集合。如果需要,您可以在此使用System.IdentityModel.Tokens中的实现。通常情况下,你不需要自己处理这个问题

public override ReadOnlyCollection<SecurityKey> SecurityKeys
{
    get { return new List<SecurityKey>().AsReadOnly(); }
}
public override SecurityKeyIdentifierClause CreateSecurityTokenReference(SecurityToken token, bool attached)
{
    if (token == null)
        throw new ArgumentNullException("token");

    return new LocalIdKeyIdentifierClause(token.Id);
}