【问题标题】:Azure B2C Claims are not coming throughAzure B2C 索赔未通过
【发布时间】:2016-04-05 21:47:01
【问题描述】:

通过 MS 网站上的示例工作,https://azure.microsoft.com/en-us/documentation/articles/active-directory-b2c-devquickstarts-web-dotnet/

一旦用户成功登录,我似乎无法获得政策(在 Azure 门户中)上设置的声明。

这里的claim对象始终为null。

var type = ClaimsPrincipal.Current.Identities.First().NameClaimType;
var claim = ClaimsPrincipal.Current.FindFirst(type);

我希望我错过了什么......

【问题讨论】:

    标签: azure azure-ad-b2c


    【解决方案1】:

    您是否检查 ClaimsPrincipal.Current.Claims?这些值存储在 ClaimsPrincipal.Current.Claims 中。我想检查您是否无法从声明页面中的以下代码中获取值。

    @foreach (Claim claim in ClaimsPrincipal.Current.Claims)
        {
            <tr>
                <td class="claim-type claim-data">@claim.Type</td>
                <td class="claim-data">@claim.Value</td>
            </tr>
        }
    

    【讨论】:

    • 嗨,是的,该列表也是空的。经过几天的努力,我已经转向了不同的身份验证策略。
    • 好的,我按照您提供的文档中的示例github.com/AzureADQuickStarts/B2C-WebApp-OpenIdConnect-DotNet,我可以从 ClaimsPrincipal.Current.Claims 中获取值,所以代码没有问题,请确保 配置正确.
    【解决方案2】:

    您的声明身份中不存在 NameIdentifier。

    Azure b2c 不提供此声明。

    【讨论】:

      【解决方案3】:

      你试试下面的代码,它工作得很好。

      ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier")
      

      ClaimsPrincipal.Current.Claims.First(x => x.Type == "extension_ClientId") 
      

      【讨论】:

        猜你喜欢
        • 2021-10-10
        • 2017-05-13
        • 1970-01-01
        • 2020-07-01
        • 1970-01-01
        • 2019-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多