Blazor WebAssembly Azure B2C Error: AADB2C90205 (insufficient permissions)
Blazor WebAssembly Azure B2C Error: AADB2C90205 (insufficient permissions)
我使用 Microsoft 文档文章中概述的步骤创建了一个示例 Blazor WebAssembly 应用程序以使用 Azure B2C 进行保护:https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-azure-active-directory-b2c?view=aspnetcore-3.1.
除了身份验证,该应用程序工作正常。 B2C 模式加载以登录,但随后 UI 显示以下错误消息。
There was an error trying to log you in: 'AADB2C90205: This application does not have sufficient permissions against this web resource to perform the operation.
这是我的 B2C 配置的一些经过编辑的屏幕截图(我确定代码是正确的,因为它是 dotnet new
CLI 命令生成的默认代码)。
对配置错误有什么想法吗?
应用注册
API - 概述
API - 身份验证
API - 公开一个 API
客户端 - 概述
客户端 - 身份验证
客户端 - API 权限
Sign-up/in 用户流程 - 概述
Sign-up/in 用户流程 - 用户属性
Sign-up/in 用户流程 - 申请声明
我可以重现你的问题。错误的原因是您使用了未经授权的资源。您需要将 scope
更改为您自己的 expose api。转到 Azure AD B2C>应用程序注册>您的客户端应用程序>API 权限。
原来问题出在代码中。
我错过了文档中的一个注释部分,该部分说如果 API ID URI 是 类似于 https://contoso.onmicrosoft.com/41451fa7-82d9-4673-8fa5-69eff5a761fd[=] 的不受信任的发布者域,我必须手动编辑客户端应用程序代码21=],我就是这样。
删除客户端应用 Program.cs
中的额外 https://{TENANT DOMAIN}/
修复了问题(注意注释掉的行和后面的行之间的区别)。
namespace BlazorClient
{
public class Program
{
public static async Task Main(string[] args)
{
...
builder.Services.AddMsalAuthentication(options =>
{
builder.Configuration.Bind("AzureAdB2C", options.ProviderOptions.Authentication);
//options.ProviderOptions.DefaultAccessTokenScopes.Add("https://***.onmicrosoft.com/https://***.onmicrosoft.com/*******/blazor.client");
options.ProviderOptions.DefaultAccessTokenScopes.Add("https://***.onmicrosoft.com/*******/blazor.client");
});
await builder.Build().RunAsync();
}
}
}
我使用 Microsoft 文档文章中概述的步骤创建了一个示例 Blazor WebAssembly 应用程序以使用 Azure B2C 进行保护:https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-azure-active-directory-b2c?view=aspnetcore-3.1.
除了身份验证,该应用程序工作正常。 B2C 模式加载以登录,但随后 UI 显示以下错误消息。
There was an error trying to log you in: 'AADB2C90205: This application does not have sufficient permissions against this web resource to perform the operation.
这是我的 B2C 配置的一些经过编辑的屏幕截图(我确定代码是正确的,因为它是 dotnet new
CLI 命令生成的默认代码)。
对配置错误有什么想法吗?
应用注册
API - 概述
API - 身份验证
API - 公开一个 API
客户端 - 概述
客户端 - 身份验证
客户端 - API 权限
Sign-up/in 用户流程 - 概述
Sign-up/in 用户流程 - 用户属性
Sign-up/in 用户流程 - 申请声明
我可以重现你的问题。错误的原因是您使用了未经授权的资源。您需要将 scope
更改为您自己的 expose api。转到 Azure AD B2C>应用程序注册>您的客户端应用程序>API 权限。
原来问题出在代码中。
我错过了文档中的一个注释部分,该部分说如果 API ID URI 是 类似于 https://contoso.onmicrosoft.com/41451fa7-82d9-4673-8fa5-69eff5a761fd[=] 的不受信任的发布者域,我必须手动编辑客户端应用程序代码21=],我就是这样。
删除客户端应用 Program.cs
中的额外 https://{TENANT DOMAIN}/
修复了问题(注意注释掉的行和后面的行之间的区别)。
namespace BlazorClient
{
public class Program
{
public static async Task Main(string[] args)
{
...
builder.Services.AddMsalAuthentication(options =>
{
builder.Configuration.Bind("AzureAdB2C", options.ProviderOptions.Authentication);
//options.ProviderOptions.DefaultAccessTokenScopes.Add("https://***.onmicrosoft.com/https://***.onmicrosoft.com/*******/blazor.client");
options.ProviderOptions.DefaultAccessTokenScopes.Add("https://***.onmicrosoft.com/*******/blazor.client");
});
await builder.Build().RunAsync();
}
}
}