本文介绍了阅读SAML从SAML令牌属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从XML文件加载SAML令牌。
I am loading SAML Token from XML file.
string certificatePath = @"D:\Projects\SAMLDemo\Server.pfx";
X509Certificate2 cert = new X509Certificate2(certificatePath, "shani");
string samlFilePath = @"D:\Projects\SAMLDemo\saml.xml";
XmlReader reader = XmlReader.Create(samlFilePath);
List<SecurityToken> tokens = new List<SecurityToken>();
tokens.Add(new X509SecurityToken(cert));
SecurityTokenResolver outOfBandTokenResolver = SecurityTokenResolver.CreateDefaultSecurityTokenResolver(new ReadOnlyCollection<SecurityToken>(tokens), true);
SecurityToken securityToken = WSSecurityTokenSerializer.DefaultInstance.ReadToken(reader, outOfBandTokenResolver);
SamlSecurityToken deserializedSaml = securityToken as SamlSecurityToken;
我怎样才能阅读SAML从deserializedSaml属性?
How can I read the SAML attributes from deserializedSaml ?
我需要的属性字符串值。
I need string values for the attributes.
推荐答案
不这项工作?
foreach (SamlStatement statement in deserializedSaml.Assertion.Statements)
{
SamlAttributeStatement attributeStatement = statement as SamlAttributeStatement;
if (null != attributeStatement)
{
foreach (SamlAttribute attribute in attributeStatement.Attributes)
{
DoWhateverYouLikeWith(attribute);
}
}
}
这篇关于阅读SAML从SAML令牌属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!