[英]How do I use the Blazor Clientside AuthorizeView control policy feature with Azure Ad?
我正在使用此鏈接中的 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) 在“組”部分擁有正確的聲明,但它沒有顯示我為該組中的用戶添加的自定義消息。
我在這個配置中遺漏了什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.