我正在使用TestWebAppCore ITfoxtec项目在ASP.NET Core中创建一个示例SAML2客户端应用程序.使用上面列出的GitHub存储库下的模板,我能够检索并显示索赔.但是,我无法正确解析和显示作为字符串列表发送的声明.
以下是使用SAML跟踪的该属性的示例结果.
<saml2:Attribute
FriendlyName="memberOf"
Name="memberOf"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
<saml2:AttributeValue>test1</saml2:AttributeValue>
<saml2:AttributeValue>test2</saml2:AttributeValue>
<saml2:AttributeValue>test3</saml2:AttributeValue>
<saml2:AttributeValue>test4</saml2:AttributeValue>
</saml2:Attribute>
在这里我们可以看到,传入的属性有一个键(MemberOf)和四个值.使用TestWebAppCore模板的ClaimsTranform.cs文件中的CreateClaimsain(ClaimsCompany IncomingRule)方法解析声明将把它转换为一个list().
private static ClaimsPrincipal CreateClaimsPrincipal(ClaimsPrincipal incomingPrincipal)
{
var claims = new List<Claim>();
// All claims
claims.AddRange(incomingPrincipal.Claims);
// Or custom claims
//claims.AddRange(GetSaml2LogoutClaims(incomingPrincipal));
//claims.Add(new Claim(ClaimTypes.NameIdentifier, GetClaimValue(incomingPrincipal, ClaimTypes.NameIdentifier)));
return new ClaimsPrincipal(new ClaimsIdentity(claims, incomingPrincipal.Identity.AuthenticationType, ClaimTypes.NameIdentifier, ClaimTypes.Role) {
BootstrapContext = ((ClaimsIdentity)incomingPrincipal.Identity).BootstrapContext
});
有没有一种方法可以正确地解析作为字符串列表传入的属性?