NabuCasa / pycognito

Python library for using AWS Cognito. With support for SRP.
Apache License 2.0
129 stars 39 forks source link

Erroneous 'UserNotFoundException' on respond_to_sms_mfa_challenge() #193

Closed jbblanton closed 1 year ago

jbblanton commented 1 year ago

When setting up login for users with SMS security enabled, I'm getting a 'User not found' exception.

import boto3
from pycognito import Cognito, MFAChallengeException
from pycognito.aws_srp import AWSSRP

def login(self):
    client = boto3.client('cognito-idp', self.region_name)
    aws = Cognito(self.pool_id, self.app_client_id, username=self.email)

    try:
        response = aws.authenticate(password=password)
    except MFAChallengeException as mfa:
        # I print the exception body; it includes a session and correct challenge parameters, and I am receiving the text code
        sms_code = input('Please check your text messages and enter the security code:')  # verified to be the correct input string
        aws.respond_to_sms_mfa_challenge(sms_code)  # done this with and without the mfa.get_tokens() value; same error

My error:
botocore.errorfactory.UserNotFoundException: An error occurred (UserNotFoundException) when calling the RespondToAuthChallenge operation: User does not exist.

I've verified the SMS code / username combo elsewhere, so it's specific to this use case.

jbblanton commented 1 year ago

Of course the fix was to simply ignore it for a few hours. I didn't change any code, but somehow things work today.