我只是想知道是否有办法通过 Azure 门户向 Azure Ad OAuth2 JWT 令牌添加或指定自定义声明?
或者这是唯一可能的代码方面?
据我所知,Azure AD目前不支持发出自定义声明。
作为解决方法,我们可以使用 Azure AD Graph 添加目录架构扩展。之后,我们可以使用 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.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)