c# - Azure B2C 身份验证(角度 + .net 核心 Web API) - 在不记名令牌中找不到范围或角色声明
问题描述
我尝试使用 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"
}
启动.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:在不记名令牌中找不到范围或角色声明。**
我不明白错误在哪里。你能帮助我吗?
谢谢
解决方案
推荐阅读
- android - 如何在 Android sip stack SipManager 中拨打我的手机号码?
- java - 如何区分呼叫是移动呼叫还是IP呼叫?
- excel - Excel中带有字符串变量的间接函数
- java - 使用 Jackson 对类扩展进行 Json 反序列化的问题 - 未找到类型返回值的转换器
- ansible - 如何传递第二个列表进行播放
- javascript - 以角度使用 ViewChild() 获取元素
- logging - 在 RavenDB 中保存结构化日志
- bdd - 一个场景大纲中多个步骤的最佳实践
- google-chrome - 身份验证后,重定向到 PWA UI 显示的是服务工作者代码
- javascript - 如何在 javascript 中实现可见性消失