Warm tip: This article is reproduced from serverfault.com, please click

其他-Blazor WebAssembly Azure B2C错误:AADB2C90205(权限不足)

(其他 - Blazor WebAssembly Azure B2C Error: AADB2C90205 (insufficient permissions))

发布于 2020-11-27 14:26:28

我创建了一个示例Blazor WebAssembly应用程序,使用Microsoft文档文章中概述的步骤通过Azure B2C对其进行保护:https ://docs.microsoft.com/zh-cn/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 newCLI命令生成的默认代码)。

对配置错误有任何想法吗?

应用注册 应用注册

API-概述 API-概述

API-身份验证 API-身份验证

API-公开API API-公开API

客户-概述 客户-概述

客户端-身份验证 客户端-身份验证

客户端-API权限 客户端-API权限

注册/登录用户流程-概述 注册/登录用户流程-概述

注册/登录用户流程-用户属性 注册/登录用户流程-用户属性

注册/登录用户流程-申请声明 注册/登录用户流程-申请声明

Questioner
TheMagnificent11
Viewed
0
TheMagnificent11 2020-12-02 22:13:22

因此,事实证明问题出在代码中。

我错过了文档中的注释部分,其中说如果API ID URI是不受信任的发布者域(类似于https://contoso.onmicrosoft.com/41451fa7-82d9-4673-8fa5-69eff5a761fd)则必须手动编辑客户端应用程序代码,该部分就我而言。

删除多余https://{TENANT DOMAIN}/Program.cs的客户端应用程序固定的东西(注意注释掉的行,之后而来的线之间的差值)。

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();
        }
    }
}