我有一个 SAML 响应,我想将其转换为 Saml2SecurityToken。这就是我所做的:
// SAMLResponseString is a base64 encode SAML2 XML string
string SAMLResponse = SamlHelper.DecodeFrom64(SAMLResponseString);
XmlReader reader = new XmlTextReader(new StringReader(SAMLResponse));
var certificate = new X509Certificate2("[path]", "[password]");
List<SecurityToken> tokens = new List<SecurityToken>();
tokens.Add(new X509SecurityToken(certificate));
SecurityTokenResolver outOfBandTokenResolver =
SecurityTokenResolver.CreateDefaultSecurityTokenResolver(new
ReadOnlyCollection<SecurityToken>(tokens), true);
var securityToken = (Saml2SecurityToken) WSSecurityTokenSerializer.DefaultInstance.ReadToken(reader, null);
在(WSSecurityTokenSerializer)的最后一行,我收到以下错误:
Cannot read the token from the 'Response' element with the 'urn:oasis:names:tc:SAML:2.0:protocol' namespace for BinarySecretSecurityToken, with a '' ValueType. If this element is expected to be valid, ensure that security is configured to consume tokens with the name, namespace and value type specified.
我的回复开始于:(< 和 samlp:Response 之间没有空格):
< samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0">
有谁知道这里出了什么问题?