我目前正在编写一个(服务器端)Blazor 应用程序,其中包含默认的 AzureAD 身份验证。
这对于经过身份验证的用户来说效果很好 - 挑战入口 ( _Host.cshtml) 文件,重定向,然后在经过身份验证后返回。
我需要有几个页面不需要身份验证 - 我不希望用户受到质询并重定向到 Microsoft。
这样做的正确方法是什么?我已经尝试过AllowAnonymousAttribute剃刀AllowAnonymousToPage页面选项,似乎没有什么可以阻止挑战。
任何帮助将不胜感激!
以下是我的身份验证设置(ConfigureServices):
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddTelerikBlazor();
}
Run Code Online (Sandbox Code Playgroud)
然后是配置中的相应部分:
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
Run Code Online (Sandbox Code Playgroud) authentication azure azure-active-directory blazor blazor-server-side