【问题标题】:How to use Kentor AuthService to get additional assertion attributes如何使用 Kentor AuthService 获取额外的断言属性
【发布时间】:2015-03-05 13:37:03
【问题描述】:

我在基于 WebForms 的应用程序中使用 Kentor HttpModule。 我需要获取使用登录声明的其他信息。我不确定,但我认为 Kentor 只解析 attributeID="userId",我需要获取更多属性。

我是否需要 fork 和修改 Kentor 才能在我的应用程序中使用这些值,或者它们存储在某个地方。

我在 Saml2Response 中看到从 AllAssertionElementNodes 方法返回的 xmlElements 集合,但我不知道如何在应用程序中访问它们。

要访问 ID,我正在使用此扩展方法:

public static string GetNameID(this IIdentity identity)
    {
        var claimsIndentity = identity as ClaimsIdentity;

        if (string.IsNullOrWhiteSpace(claimsIndentity)
        {
            return string.Empty;
        }

        var providerQuery = from c in claimsIndentity.Claims
                            where c.Type.EndsWith("/identity/claims/nameidentifier")
                            select c.Value;

        var provider = providerQuery.FirstOrDefault();

        return provider;
    }

还有这个:

if (User.Identity.IsAuthenticated)
 {
     userId = User.Identity.GetNameID();
 }

有什么建议吗?

更新

我相信这是一个合适的解决方案。在 AcsCommandProcessResponse 方法中,我们有一个 samlResponse InnerXML,从那里我们可以解析想要的数据,创建额外的声明,或者其他什么,所以现在我有了一个解决方案(解决方法可能是我的问题)。还有其他更优雅的解决方案吗?

【问题讨论】:

    标签: c# saml-2.0 claims-based-identity kentor-authservices


    【解决方案1】:

    Kentor.AuthServices SP 将断言中的所有属性转换为声明。如果您在GetNameID 方法中设置断点并检查claimsIdentity.Claims 枚举,则所有属性都应该存在。如果不是,请在AuthService github page 上提出问题。

    【讨论】:

    • 是的,他们在那里。非常感谢!这比我的更优雅的解决方案。我编写了一个自定义解析器来从响应 XML 中提取它们。此外,我没有看到您在 IdP 解决方案中使用相同的逻辑将所有其他声明转换为属性。将所有声明转换为属性是否有任何缺点,反之亦然?我的意思是我的情况可以正常工作,但一般来说?
    • 不,属性和声明实际上只是同一事物的两个名称。在极少数需要过滤声明的情况下,可以通过ClaimsAuthenticationManager 来完成。
    • 我是否也可以在不制作自己的解析器的情况下以某种方式访问​​ saml2:Subject saml2:NameID 值?
    • NameID 也被翻译成声明。
    • 代码在哪里?我看到所有陈述都被翻译成属性,而属性又被翻译成声明。但是对于这个主题,该主题仅用于生成 XElement。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 2019-01-06
    • 1970-01-01
    相关资源
    最近更新 更多