我尝试使用 MSAL-angular 和 Azure B2C 进行 angular 应用程序进行身份验证。 我能够使用 Azure B2C 对 Angular 应用程序进行身份验证(我已经创建了一个 susi 流)并获得了如下图所示的令牌
所以我创建了一个 .net core web api 项目并修改了 appsetting 配置并使用此代码启动:
appsetting.json :
"AzureAdB2C": {
"Instance": "https://{mytenat}.b2clogin.com/tfp",
"ClientId": "8xxxx-xxxx-xxxx-xxxx-xxxxxxxxc",
"Domain": "{mytenat}.onmicrosoft.com",
"SignUpSignInPolicyId": "B2C_1_susi"
}
startup.cs
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(options =>
{
Configuration.Bind("AzureAdB2C", options);
options.TokenValidationParameters.RoleClaimType = "roles";
options.TokenValidationParameters.NameClaimType = "name";
},
options => { Configuration.Bind("AzureAdB2C", options); });
// By default, the claims mapping will map claim names in the old format to accommodate older SAML applications.
//'http://schemas.microsodt.com/ws/2008/06/identity/clains/role' instead of 'roles'
// This flag ensures that the ClaimsIdentity claims collection will be build from the claims in the token
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
//services.Configure<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme, options =>
//{
// // The claim in the Jwt token where App roles are available.
// options.TokenValidationParameters.RoleClaimType = "roles";
//});
但是如果我尝试在本地运行项目并使用邮递员调用它,我会遇到此错误:
**System.UnauthorizedAccessException:IDW10201:在不记名令牌中找不到范围或角色声明。 **
我不明白错误在哪里。 你能帮我吗?
谢谢