我有一個使用 Microsoft.AspNetCore.Identity 的 Blazor 服務器應用程式。用戶進行身份驗證(使用 IdentityServer),然后可以查看頁面,具體取決于他們的角色。我以兩種方式之一檢查角色。在頁面的開頭:
@attribute [Authorize(Roles = "some_user_role")]
或在代碼塊中:
<AuthorizeView Roles="some_user_role">
</AuthorizeView>
在我的Startup.cs課程中,我有這個:
public void ConfigureServices(IServiceCollection services)
{
//db connection stuff
services.AddDefaultIdentity<CustomUserContext>(options =>
options.SignIn.RequireConfirmedAccount = true)
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddClaimsPrincipalFactory<UserClaimsPrincipalFactory<CustomUserContext>>();
// do other stuff
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//other stuff
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
但是,當我使用憑據進行身份驗證時,即使我帳戶的 EmailConfirmed 為 false,我仍然可以訪問需要“some_user_role”角色的內容。如何強制執行 EmailConfirmed?在他們確認之前,我是否必須洗掉用戶角色?
謝謝
uj5u.com熱心網友回復:
幾乎是的。電子郵件確認與帳戶作業無關 - 可以重置,即更改電子郵件。
做任何你的邏輯要求。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/333937.html
