![](/img/trans.png)
[英]IDW10201: Neither scope or roles claim was found in the bearer token. custom web api core
[英]Azure B2C Authentication (angular + .net core Web API) - Neither scope or roles claim was found in the bearer token
我嘗試使用 MSAL-angular 和 Azure B2C 進行 angular 應用程序進行身份驗證。 我能夠使用 Azure B2C 驗證 angular 應用程序(我創建了一個 susi 流)並獲得令牌,如下圖所示
所以我創建了一個 .net 核心 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";
//});
但是如果我嘗試在本地運行項目並使用 postman 調用它,我會遇到此錯誤:
**System.UnauthorizedAccessException:IDW10201:在不記名令牌中找不到 scope 或角色聲明。 **
我不明白錯誤在哪里。 你能幫助我嗎?
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.