【发布时间】:2021-10-12 17:23:08
【问题描述】:
我尝试在 dotnet 5.0 微服务 webapi 中对 Azure AD B2C 应用进行身份验证失败。
我参考了在以下位置托管的项目的教程:https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2.git
在 Startup.cs 文件的 ConfigureServices 下,我根据示例项目尝试了以下操作:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(
options => {
Configuration.Bind("AzureAdB2C", options);
options.TokenValidationParameters.NameClaimType = "name";
},
options => { Configuration.Bind("AzureAdB2C", options);}
);
我收到以下错误消息:
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler: Error: Exception occurred while processing message.
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://xxxxxx.b2clogin.com/Tenant-xxx-xxx-xxx-xxxxxxID/v2.0/.well-known/openid-configuration'
---> System.IO.IOException: IDX20807: Unable to retrieve document from: 'https://xxxxxx.b2clogin.com/Tenant-xxx-xxx-xxx-xxxxxxID/v2.0/.well-known/openid-configuration'. HttpResponseMessage: 'StatusCode: 404, ReasonPhrase: 'Not Found', ...
我还尝试了以下方法:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(Configuration.GetSection("AzureAdB2C"));
以上这个认证方式返回登录模板html页面。
参考未在 appsettings.json 中包含 TenantId 的项目,我收到错误消息,抱怨缺少 TenantId。所以现在在 appsettings.json 中,我有以下详细信息:
"AzureAdB2C": {
"Instance": "https://xxxxxx.b2clogin.com/",
"ClientId": "xxxx-xxx-xxx-xx-xxxx",
"Domain": "xxxxxx.onmicrosoft.com/",
"SigninPolicyId":"B2C_1_testsusi",
"TenantId": "Tenant-xxx-xxx-xxx-xxxxxxID"
}
非常感谢任何帮助!
【问题讨论】:
标签: azure .net-core oauth-2.0 azure-ad-b2c