Search code examples
asp.net-identityasp.net-core-6.0

How to forbid automatic redirection from /Identity/Account/Login to /Identity/Account/LoginWith2fa in DefaultUI


I use my own custom user story for site users. After login page (/Identity/Account/Login) DefaultUI call IUserStore_FindByIdAsync than automatically redirect to (/Identity/Account/LoginWith2fa). How to control this redirection?

 Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executing endpoint '/Account/LoginWith2fa'
 Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Information: Route matched with {page = "/Account/LoginWith2fa", area = "Identity", action = "", controller = ""}. Executing page /Account/LoginWith2fa
 Microsoft.EntityFrameworkCore.Infrastructure: Information: Entity Framework Core 6.0.7 initialized 'ApplicationDbContext' using provider 'Pomelo.EntityFrameworkCore.MySql:6.0.2' with options: CommandTimeout=10 ServerVersion 10.5.9-mariadb 
 Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Information: Executing handler method      Microsoft.AspNetCore.Identity.UI.V5.Pages.Account.Internal.LoginWith2faModel.OnPostAsync - ModelState is Valid
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserStore_FindByIdAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserStore_FindByIdAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserLockoutStore_GetLockoutEnabledAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserAuthenticatorKeyStore_GetAuthenticatorKeyAsync
 Microsoft.AspNetCore.Identity.UserManager: Warning: VerifyTwoFactorTokenAsync() failed for user.
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserLockoutStore_IncrementAccessFailedCountAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserStore_GetUserNameAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserStore_FindByNameAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserStore_GetUserIdAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserStore_GetUserIdAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserStore_GetUserNameAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserStore_SetNormalizedUserNameAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserStore_UpdateAsync
 BackendAPI.Services.CustomUserStore: Information: 456780: IUserStore_GetUserIdAsync
 Microsoft.AspNetCore.Identity.UI.V5.Pages.Account.Internal.LoginWith2faModel: Warning: Invalid authenticator code entered.

I want to register user easy as possible, maybe with time need to require form user various additional difficulties like 2FA, confirm PhoneNumber and other.
But now when I return user from IUserStore_FindByIdAsync DefaultUI immediately doing automatic redirection to 2FA form. For me this is strange and very useless logic.

2Fa

What I need and where to control this redirection?


Solution

  • GetTwoFactorEnabledAsync need to return false, this is avoid redirection to /Identity/Account/LoginWith2fa