Search code examples
asp.netasp.net-mvcasp.net-identityidentityclaims-based-identity

RequireConfirmedEmail for normal logins but not external logins (identity core)


setting RequireConfirmedEmail at identity options returns SignInResult.NotAllowed on the result of signing the user in, it's tested at CanSignInAsync

if (Options.SignIn.RequireConfirmedEmail && !(await UserManager.IsEmailConfirmedAsync(user)))

but this apply to external logins too, which is a behaviour we would like to only have on normal logins

we already know that we can extend the SignInManager<TUser> but we thought maybe someone have a simpler more elegant solution, anyone ?


Solution

  • The easiest solution is to set EmailConfirmed = true when you create the external user, like in the default template method ExternalLoginConfirmation:

    var user = new ApplicationUser { UserName = model.Email, 
                                     Email = model.Email, 
                                     EmailConfirmed = true };