C
C#4mo ago
hutoanhill

Identity 2FA wont enable

working in implementing my own login procedures. I've got a /register endpoint. this is mostly like the default, but it enables/resets 2FA.
...
// turn on 2FA and get the key
await userManager.SetTwoFactorEnabledAsync(user, true);

// get the newly defined key
string? key = await userManager.GetAuthenticatorKeyAsync(user);

// make sure we get the key.
if (string.IsNullOrEmpty(key)) {
await userManager.ResetAuthenticatorKeyAsync(user);
key = await userManager.GetAuthenticatorKeyAsync(user);

if (string.IsNullOrEmpty(key)) {
throw new NotSupportedException("The user manager must produce an authenticator key.");
}
}

// Return the shared key and indicate successful registration
return TypedResults.Ok(new RegistrationResponse(key));
...
// turn on 2FA and get the key
await userManager.SetTwoFactorEnabledAsync(user, true);

// get the newly defined key
string? key = await userManager.GetAuthenticatorKeyAsync(user);

// make sure we get the key.
if (string.IsNullOrEmpty(key)) {
await userManager.ResetAuthenticatorKeyAsync(user);
key = await userManager.GetAuthenticatorKeyAsync(user);

if (string.IsNullOrEmpty(key)) {
throw new NotSupportedException("The user manager must produce an authenticator key.");
}
}

// Return the shared key and indicate successful registration
return TypedResults.Ok(new RegistrationResponse(key));
The issue is when i try to log in it says 2FA is not enabled for the user.
var result = await signInManager.PasswordSignInAsync(login.Email, login.Password, isPersistent, lockoutOnFailure: true);

if (result.RequiresTwoFactor) { // this is false
var result = await signInManager.PasswordSignInAsync(login.Email, login.Password, isPersistent, lockoutOnFailure: true);

if (result.RequiresTwoFactor) { // this is false
as far as i can tell await userManager.SetTwoFactorEnabledAsync(user, true); should flip that switch that requires 2FA but its not? is this something i have to change in set up? some option to change when i add identity?
2 Replies
hutoanhill
hutoanhillOP4mo ago
bump :(
❤RieBi&❤
❤RieBi&❤4mo ago
Sad, no one helped you
Want results from more Discord servers?
Add your server