【发布时间】:2021-02-05 09:00:51
【问题描述】:
我要做的是在身份验证后添加声明。
以下注册OnTokenValidation 事件的示例无法解决问题。该事件永远不会触发。
我正在使用 Microsoft.Identity.Web 在 Azure AD B2C 上进行身份验证。那部分有效!
如何使用AddMicrosoftIdentityWebAppAuthentication 注册事件?
services.AddMicrosoftIdentityWebAppAuthentication(Configuration, "AzureAdB2C")
.EnableTokenAcquisitionToCallDownstreamApi(new string[] {Configuration["DemoApi:ServiceScope"]})
.AddInMemoryTokenCaches();
services.Configure<OpenIdConnectOptions>(AzureADB2CDefaults.OpenIdScheme, options =>
{
options.Events = new OpenIdConnectEvents
{
OnTokenValidated = ctx =>
{
//query groups with graph api to get the role
// add claims
var claims = new List<Claim>
{
new Claim(ClaimTypes.Role, "superadmin")
};
var appIdentity = new ClaimsIdentity(claims);
ctx.Principal.AddIdentity(appIdentity);
return Task.CompletedTask;
},
};
});
【问题讨论】:
标签: .net azure-ad-b2c roles .net-core-3.1 claims