【问题标题】:How to proof the token claims in a .NET Core Web Api for Azure Active Directory security check如何在 .NET Core Web Api 中证明令牌声明以进行 Azure Active Directory 安全检查
【发布时间】:2019-02-07 21:35:27
【问题描述】:

当收到授权的 POST 请求时,我将证明令牌的声明。你在下面找到我的代码。我在每一行都设置了断点。但是从线

`    policy.RequireAssertion(context =>`

编译器直接跳转到方法的末尾。 在我做这个证明之前我需要一些其他的东西还是我需要改变语法。 得到帮助会很高兴。 弗兰克

`    services.AddAuthorization(configure =>
{
    configure.AddPolicy("AccessControllerClaimGroupGUIDPolic", policy =>
    {
        policy.RequireAssertion(context =>
        {
            return context.User.HasClaim(c =>
            {
                return (c.Type == "groups" && AllowedClaimsGroupIds.Contains(c.Value)) || (c.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier" && AllowedClaimsOId.Contains(c.Value));
            });
        });
    });
});`

【问题讨论】:

    标签: azure-active-directory asp.net-core-webapi policy


    【解决方案1】:

    @弗兰克,

    你可以试试下面的代码:-

     policy.RequireAssertion(context =>
                        {
                            var checkIfUserHasClaim= context.User.HasClaim(c =>
                            {
                                c.Type == "groups" && AllowedClaimsGroupIds.Contains(c.Value) || (c.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier" && AllowedClaimsOId.Contains(c.Value));
                            });
                            return checkIfUserHasClaim;
                        })

    public IActionResult Index()
            {
                bool hasClaim = HttpContext.User.HasClaim(c =>
                                   c.Type == "groups" || (c.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier")
                               );
               // return hasClaim;
                return View();
            }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-05
      • 2021-10-25
      • 2018-03-10
      • 1970-01-01
      • 2017-02-17
      • 1970-01-01
      • 2016-10-22
      • 1970-01-01
      相关资源
      最近更新 更多