我SecurityToken用Saml2SecurityToken以下内容创建:
SecurityToken st = new Saml2SecurityToken(
new Saml2Assertion(new Saml2NameIdentifier("localUser"))
{
Statements =
{
new Saml2AttributeStatement(new List<Saml2Attribute>()
{
new Saml2Attribute(
"http://identityserver.thinktecture.com/claims/identityprovider",
"promProvider")
}),
new Saml2AuthenticationStatement(new Saml2AuthenticationContext(
new Uri("urn:oasis:names:tc:SAML:2.0:ac:classes:Password")))
},
Subject = new Saml2Subject(new Saml2NameIdentifier("administrator")) {
SubjectConfirmations = { new Saml2SubjectConfirmation(
new Uri("urn:oasis:names:tc:SAML:2.0:cm:bearer"))}},
SigningCredentials = new SigningCredentials(
new X509AsymmetricSecurityKey(certificate),
SecurityAlgorithms.RsaSha256Signature,
SecurityAlgorithms.Sha256Digest,
new SecurityKeyIdentifier() { new X509RawDataKeyIdentifierClause(certificate) })
}, new ReadOnlyCollection<SecurityKey>(new List<SecurityKey>()), securityToken);
所有这些都用于为在安全协议上运行的服务创建代理:WS2007FederationHttpBinding并且它成功运行,我不会详细介绍,因为问题的本质是不同的。问题如下,有些台词是我用手规定的,我不太喜欢,即:
"urn:oasis:names:tc:SAML:2.0:ac:classes:Password"- 身份验证上下文类 URI"urn:oasis:names:tc:SAML:2.0:cm:bearer"- 主题确认方法
是否有任何参考资料可以让我获得这些行,例如,枚举或存储它的类,这样的计划:
// "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
var rsaSha256Signature = SecurityAlgorithms.RsaSha256Signature;
// "http://www.w3.org/2001/04/xmlenc#sha256"
var sha256 = SecurityAlgorithms.Sha256Digest;
如果有,我在哪里可以买到它们?
解决方法是:
SecurityToken通过SecurityTokenDescriptorwith创建Saml2SecurityTokenHandler。在这种情况下,不需要常量。结果,代码变小了,代码也变得好看了:我在用户@PavelMayorov 的建议帮助下解决了这个问题,特别感谢他。但是我没有找到常量,如果找到了,我会添加到我的答案中。
遵循了另一个关于使用
X509SigningCredentialsinstead的建议,SigningCredentials并得到了适合我的最终结果:一切工作稳定。