amplify-js icon indicating copy to clipboard operation
amplify-js copied to clipboard

Resend MFA Code API

Open aoloo opened this issue 4 years ago • 55 comments

Is your feature request related to a problem? Please describe. Our workflow MFA is required in Cognito via (SMS). The user enters the login username and password and is redirected to verify the MFA code page. Now comes the edge case where a user does not receive the MFA code due to network issues or other interference. Therefore we need to provide users with the option to resend an MFA code.

Describe the solution you'd like A method to resend MFA Code due to some edge case a user does not receive a code within the initial sign In flow. A similar hook to Auth.resendSignUp() but for MFA Code.

Describe alternatives you've considered Calling the Auth.SignIn() to resend MFA Code is not ideal because signIn requires a username and password.

aoloo avatar Aug 28 '20 14:08 aoloo

@aoloo

doing Auth.signIn(..) will resend the code, in that case you will need to store in memory the username and password for that purpose.

elorzafe avatar Aug 28 '20 21:08 elorzafe

@elorzafe @amhinson we are currently implementing that, but the authentication code does not always get sent. There some instances where calling Auth.signIn() does not work.

try {
  const user = await Auth.signIn(username,password);
} catch (err) {
   `Code was not sent successfully!`
 }

This is my current implementation within a on click event when a user clicks a resend-mfa code on a form. It will be really nice to have a resendMFA api call. This can benefit the community implementing MFA.

aoloo avatar Aug 31 '20 12:08 aoloo

@elorzafe Just to note when calling Auth.signIn it returns {"__type":"CodeMismatchException","message":"Invalid code or auth state for the user."}. So it is crucial that we have an api for re sending mfa authentication code.

aoloo avatar Sep 01 '20 10:09 aoloo

Seconding! This is an issue for me as well. Would be great if I could resend confirmation codes, without having to make users re-sign in.

mitchgillin avatar Sep 01 '20 13:09 mitchgillin

Yeah, also seeing this. We'll workaround with posting to Auth.logIn again, but it does feel like there ought to be an api method for this - it's the only part of the sign up/sign in/reset password etc... workflows that doesn't have a re-send.

pinpointpanda avatar Sep 08 '20 12:09 pinpointpanda

This has been an issue for us for quite some time. I don't like having to hold on to a password in order to call Auth.signIn again for this feature, and asking users to sign in again is really clunky.

cezarcarvalhaes avatar Sep 10 '20 14:09 cezarcarvalhaes

@harrysolovay @elorzafe any movement on this?

aoloo avatar Sep 30 '20 18:09 aoloo

Has anyone heard any update on this issue?

MaxwellOldshein avatar Jan 25 '21 19:01 MaxwellOldshein

Just want to add my name to the list of people who would need this feature. I am not using the Amplify framework though. Only the php SDK. But it's visibly kind of all the same !

martinlanglois avatar Mar 04 '21 22:03 martinlanglois

Just want to add my name to the list of people who require this feature. This is a blocker for my project.

chaawlaapooja avatar Mar 30 '21 08:03 chaawlaapooja

This is a blocker on one of my projects as well.

Thomsen-c avatar Jun 21 '21 13:06 Thomsen-c

Same here... there's some update?

pedrohff360 avatar Dec 01 '21 19:12 pedrohff360

+1, this is a needed feature

justinslalom avatar Dec 10 '21 21:12 justinslalom

+1 This is very basic feature request at this point. Specially since we would like to send a code to actually validate the MFA before actually enabling it, to confirm the user has access to the phone/email. AWS enabled it right away, without validating anything. And it is funny, since AWS actually ask you for TWO codes before enabling.

sfratini avatar Dec 27 '21 14:12 sfratini

+1

tigrenok00 avatar Feb 06 '22 08:02 tigrenok00

+1

eugendorin avatar Feb 11 '22 12:02 eugendorin

+1

jwelfare avatar Feb 25 '22 22:02 jwelfare

Any update on this issue? This is a blocker on one of my projects as well.

44mkashif avatar Mar 09 '22 18:03 44mkashif

Need update on this

gluonfield avatar Apr 07 '22 17:04 gluonfield

Seeking update as well

Levisnkyyyy avatar Apr 25 '22 10:04 Levisnkyyyy

Is there any update on this? The given "workaround" of using Auth.SignIn() does not seem to actually work.

madlerpar avatar May 23 '22 16:05 madlerpar

+1, this is a needed feature

Muzammil98 avatar Jul 18 '22 09:07 Muzammil98

If anyone is still looking for this solution here is my workaround/solution.

So to resend OTP code you should do Auth.signIn(email, password) again and update the user object with new response and do Auth.confirmSignIn(user, otp, user.challengename) with updated user object.

Here is my code:

...
const [user, setUser] = useState()
...
 const handleSubmitMfa = async () => {
    if (user) {
      if (user.challengeName === 'SMS_MFA' || user.challengeName === 'SOFTWARE_TOKEN_MFA') {
        try {
          await Auth.confirmSignIn(user, otp, user.challengeName)
          router.push('/')
        } catch (err: any) {
          if (err.code === 'CodeMismatchException') {
            setError('Invalid OTP Code')
          }
        }
      } else if (user.challengeName === 'MFA_SETUP') {
        Auth.setupTOTP(user)
      }
    }
  }

  const handleResend = async () => {
    if (user && user.challengeName === 'SMS_MFA') {
      const userRes = await Auth.signIn(values.email, values.password)
      // Update user object to confirm sign in with newly received code.
      setUser(userRes)
    }
  }

Hope it helps!

JJ810 avatar Jul 18 '22 17:07 JJ810

The solution provided by @JJ810 seems to work just fine (thank you) but we really need this feature.

LazyAfternoons avatar Aug 02 '22 13:08 LazyAfternoons

Hello everyone! Our team is working on introducing this as a feature of our library in a future iteration. We will provide an update on this Github issue when a new version is out. We do not yet have exact timelines, but we will share them once they are known to us!

abdallahshaban557 avatar Aug 09 '22 00:08 abdallahshaban557

I too need a solution that does not require me to cache the password... seems pretty insecure. Thankfully I'm doing this server-side. Still would prefer an API that would just resend the code

kceb avatar Oct 14 '22 05:10 kceb

+1, this is a needed feature

ovidiu-a avatar Oct 18 '22 08:10 ovidiu-a

Cognito does not currently provide the ability for us to resend the MFA code. Until they provide this functionality, we cannot implement in amplify. We will continue to stress the importance of this issue internally and provide an update as soon as we have one.

erinleigh90 avatar Nov 09 '22 19:11 erinleigh90

Closing this as a duplicate of #2010

abdallahshaban557 avatar Nov 10 '22 15:11 abdallahshaban557

@abdallahshaban557 I would prefer we close #2010 and keep this one open. It is more active and recent. Thanks!

aoloo avatar Nov 10 '22 15:11 aoloo