如何使用 Kentor AuthService 获取额外的断言属性

How to use Kentor AuthService to get additional assertion attributes

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

我是否需要分叉和修改 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();
 }

有什么建议吗?

更新

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

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

上提交问题