gpt4 book ai didi

c# - 添加 Azure Ad Oauth2 JWT token 声明

转载 作者:行者123 更新时间:2023-11-30 12:40:16 25 4
gpt4 key购买 nike

我只是想知道是否有办法通过 Azure 门户向 Azure Ad OAuth2 JWT token 添加或指定自定义声明?或者这是唯一可能的代码方面?

最佳答案

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

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

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 提交。 .

关于c# - 添加 Azure Ad Oauth2 JWT token 声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42434254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com