question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auth.setupTOTP - Invalid session for the user

See original GitHub issue

Describe the bug I set up Amplify with Cognito authentication with SMS MFA enabled. I have configured my own UI to provide the credentials and it used to work just fine. However, the SMS text messages suddenly stopped being delivered. I could tell the messages were trying to be sent. CloudWatch had the errors logged and said “Phone is currently unreachable/unavailable.” In all the research I’ve done, I haven’t been able to find a reason why. Increased spending limits did not solve the problem. I encountered another issue that sounded similar [#5137] and although it wasn’t technically resolved I decided to implement the workaround from that issue.

The workaround was to implement TOTP MFA. However, I am unable to get it to work. Every time

Auth.setupTOTP(user)

is called, I get this error:

{code: "NotAuthorizedException", name: "NotAuthorizedException", message: "Invalid session for the user."}

This is the CognitoUser object returned from the sign in method provided by Amplify:

{
  Session: "xxxxxx"
  authenticationFlowType: "USER_SRP_AUTH"
  challengeName: "SMS_MFA"
  challengeParam: {CODE_DELIVERY_DELIVERY_MEDIUM: "SMS", CODE_DELIVERY_DESTINATION: "+*******9088"}
  client: Client {endpoint: "https://cognito-idp.us-west-2.amazonaws.com/", userAgent: "aws-amplify/0.1.x js"}
  keyPrefix: "CognitoIdentityServiceProvider.xxx"
  pool: CognitoUserPool {userPoolId: "us-west-2_xxx", clientId: "xxx", client: Client, advancedSecurityDataCollectionFlag: true, storage: Storage}
  signInUserSession: null
  storage: Storage {aws.cognito.identity-id.us-west-2:xxx: "us-west-2:xxx", aws.cognito.identity-id.us-west-2:xxx: "us-west-2:xxx", CognitoIdentityId-us-west-2:xxx: "us-west-2:xxx", CognitoIdentityId-us-west-2:xxx: "us-west-2:xxx", length: 4}
  userDataKey: "CognitoIdentityServiceProvider.xxx.michael.userData"
  username: "michael"
}

The Session variable has a value, but the signInUserSession variable is null. I assume the signInUserSession being null is the reason why this isn’t working.

To Reproduce Steps to reproduce the behavior:

  1. Configure app via amplify cli to have MFA (TOTP) required
  2. Sign up a new user (confirm email and everything)
  3. Sign in newly created user using Auth.signIn
  4. Attempt to set up MFA TOTP via Auth.setupTOTP with the user object returned from the sign in method

Expected behavior Auth.setupTOTP(user) would accept the user object returned from the Auth.signIn(username, password) method to allow MFA TOTP to be configured. With this, the setupMFA method would return a code to generate a QR code for end user to configure their Authenticator application.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:27 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
apolegoshkocommented, Apr 28, 2021

Just wanna confirm that following workflow works: initiateAuth -> associcateSoftwareToken -> VerifySoftwareToken -> RespondToAuthChallenge.

2reactions
austinhinderercommented, Nov 12, 2020

I’m currently seeing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auth.setupTOTP - Invalid session for the user - Bountysource
I set up Amplify with Cognito authentication with SMS MFA enabled. I have configured my own UI to provide the credentials and it...
Read more >
Cognito - adminRespondToAuthChallenge returns Invalid ...
Step 2: The user receives an OTP which gets returned to Cognito through adminRespondToAuthChallenge(). Step 3: The first time all works fine.
Read more >
AssociateSoftwareToken - Amazon Cognito User Pools
Begins setup of time-based one-time password (TOTP) multi-factor authentication (MFA) for a user, with a unique private key that Amazon Cognito generates ...
Read more >
Multi-factor authentication - JavaScript - AWS Amplify Docs
Setup TOTP. With TOTP (Time-based One-time Password), your app user is challenged to complete authentication using a time-based one-time ...
Read more >
How to use the @aws-amplify/auth.setupTOTP function ... - Snyk
To help you get started, we've selected a few @aws-amplify/auth.setupTOTP examples, based on popular ways it is used in public projects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found