添加 Azure Ad Oauth2 JWT 令牌声明

Adding Azure Ad Oauth2 JWT Token Claims(添加 Azure Ad Oauth2 JWT 令牌声明)
本文介绍了添加 Azure Ad Oauth2 JWT 令牌声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否可以通过 Azure 门户向 Azure Ad OAuth2 JWT 令牌添加或指定自定义声明?还是这只是可能的代码方面?

I was just wondering if there is a way to add or specify custom claims to the Azure Ad OAuth2 JWT token via Azure Portal? Or is this only possible code side?

推荐答案

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

As far as I know, the Azure AD doesn't support to issue the custom claim at present.

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

As a workaround, we can use the Azure AD Graph to add the directory schema extensions. After that, we can use the Azure AD Graph to get the data extension and add the custom claim when the security token is verified like code below:

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 有任何想法或反馈,可以从 这里.

In addition if you have any idea or feedback about Azure, you can submit them from here.

这篇关于添加 Azure Ad Oauth2 JWT 令牌声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)