VS 使用 Azure B2C 生成的 Blazor WebAssembly 应用程序显示 AADB2C90205

问题描述 投票:0回答:1

我正在尝试在我的开发计算机上获取本地 Web 应用程序以使用 Azure B2C 作为用户帐户,但我遇到了一个似乎“开箱即用”的错误代码,这非常令人沮丧。

在 Windows 11 计算机上使用 Visual Studio Studio Community 2022(64 位)(版本 17.9.5)创建了一个新的 Blazor WebAssembly 独立应用程序(.Net 8.0,身份验证类型=Microsoft Identity Platform)。 创建项目后,VS 要求我连接到我的 Azure 帐户,以便它可以创建 B2C 租户并进行必要的连接。一切看起来都很好并成功完成。

当我运行该应用程序时,它会向我显示示例 Blazor Web 应用程序。我单击“登录”超链接,弹出的浏览器窗口向我显示 Azure B2C,我可以在其中创建新帐户或登录。 创建新帐户已成功在我的 Azure B2C 帐户中创建新的用户帐户。

登录或创建新用户帐户后,它会重定向到我本地托管的 Web 应用程序。 然后它会显示以下消息:

There was an error trying to log you in: 'undefined - [undefined]: AADB2C90205: This application does not have sufficient permissions against this web resource to perform the operation. 
Correlation ID: a33b8507-93f9-475d-b9ed-b2c8554b0db7 Timestamp: 2024-04-22 21:50:20Z - Correlation ID: undefined - Trace ID: undefined'

所有这些都是由 VS 提示生成的,所以我希望它无需调试或修改即可工作。我怀疑我需要进入 Azure 并向租户添加一些权限,但我不确定在哪里或做什么。任何指导将不胜感激。

azure-active-directory azure-ad-b2c blazor-webassembly
1个回答
0
投票

我创建了 Blazor WebAssembly Standalone 应用程序 .net 8 并选择身份验证类型作为 Microsoft Identity Platform。

我将此行 @attribute [Authorize] 添加到 Counter.razor 页面。

下面是我完整的 Counter.razor 页面。

@page "/counter"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
    }
}

运行我的应用程序时,我遇到了同样的问题,因此我取消选中应用程序注册中的身份验证下的Access TokenID Token选项,如下所示。

enter image description here

确保您的重定向 URL 正确。

enter image description here

如果您在 ApI 权限中添加 Microsoft graph 权限,请授予管理员同意,如下所示。

enter image description here

输出

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.