加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 添加Azure Ad Oauth2 JWT令牌声明

发布时间:2020-12-15 22:42:09 所属栏目:百科 来源:网络整理
导读:我只是想知道是否有办法通过Azure门户添加或指定Azure Ad OAuth2 JWT令牌的自定义声明? 或者这只是可能的代码方面? 解决方法 据我所知,Azure AD目前不支持发布自定义声明. 作为解决方法,我们可以使用Azure AD Graph添加directory schema extensions.之后,
我只是想知道是否有办法通过Azure门户添加或指定Azure Ad OAuth2 JWT令牌的自定义声明?
或者这只是可能的代码方面?

解决方法

据我所知,Azure AD目前不支持发布自定义声明.

作为解决方法,我们可以使用Azure AD Graph添加directory schema extensions.之后,我们可以使用Azure AD Graph获取数据扩展,并在验证安全令牌时添加自定义声明,如下所示:

app.USEOpenIdConnectAuthentication(
    new OpenIdConnectAuthenticationOptions
    {
        ClientId = clientId,Authority = authority,PostLogoutRedirectUri = postLogoutRedirectUri,Notifications = new OpenIdConnectAuthenticationNotifications
        {
            AuthenticationFailed = context => 
            {
                context.HandleResponse();
                context.Response.Redirect("/Error?message=" + context.Exception.Message);
                return Task.FromResult(0);
            },SecurityTokenValidated = context =>
            {
                //you can use the Azure AD Graph to read the custom data extension here and add it to the claims 
                context.AuthenticationTicket.Identity.AddClaim(new System.Security.Claims.Claim("AddByMe","test"));
                return Task.FromResult(0);
            }
    });

此外,如果您对Azure有任何想法或反馈,可以从here提交.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读