我正在使用此链接中的 Microsoft 示例 https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/standalone-with-azure-active-directory?view=aspnetcore-3.1
我的 Program.cs 文件看起来像这样
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.Services.AddScoped(sp =>
new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddAuthorizationCore(config =>
{
config.AddPolicy("BackOfficeEditor", policy =>
policy.RequireClaim("groups", "4dd6726b-3949-4b8a-a8e0-9e5eaa65e358"));
});
builder.Services.AddMsalAuthentication(options =>
{
builder.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication);
});
await builder.Build().RunAsync();
}
}
我的 index.razor 文件看起来像这样
@page "/"
<AuthorizeView Policy="BackOfficeEditor">
<p>You can only see this if you satisfy the
<b style="color:magenta;font-size:larger">
BackOfficeEditor</b> policy.</p>
</AuthorizeView>
<AuthorizeView>
<NotAuthorized>
<br />
You are not logged in
<br />
</NotAuthorized>
<Authorized>
<br />
Hello, @context.User.Identity.Name! <br />
<h2>here's the list of your claims:</h2>
<ul>
@foreach (var claim in context.User.Claims)
{
<li><b>@claim.Type</b>: @claim.Value</li>
}
</ul>
</Authorized>
</AuthorizeView>
您可以在声明中看到用户 (minonOne) 在“组”部分拥有正确的声明,但它不显示我为该组中的用户添加的自定义消息。
我在这个配置中错过了什么?