aws-amplify / aws-sdk-android

AWS SDK for Android. For more information, see our web site:
https://docs.amplify.aws
Other
1.03k stars 549 forks source link

User Pool getSessionInBackground retrieve UserNotFoundException #366

Closed miguelguzmanconde closed 6 years ago

miguelguzmanconde commented 6 years ago

To help us solve your problem better, please answer the following list of questions.

***Here is some parts of the code im using

        UserPoolManager.getInstance(mContext).login(
                email.getText().toString(), pass.getText().toString(), townListener
        ); //the email and password are setted in code in a EditText

public void login(String email, String pass, TownListener townListener) {
    this.email = email; this.pass = pass; this.townListener = townListener;

    if(userPool == null) townListener.onError("not initialized UserPool");
    else {
        cognitoUserPool = new UserPoolManager();
        userPool.getUser(email).getSessionInBackground(signInCallback);
    }
}

private AuthenticationHandler signInCallback = new AuthenticationHandler() {

    @Override
    public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {

        if(userSession.isValid()) {
            CognitoManager.getInstance().setUserPool(userSession.getIdToken().getJWTToken());

            userPool.getCurrentUser().getDetailsInBackground(detailsListener);
        } else townListener.onError("Token ha quedado inutilizado por razones de seguridad.");

    }

    @Override
    public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation,
                                         String userId) {
        GLog.i("getAuthenticationDetails.continuation(): " + authenticationContinuation.toString());
        authenticationContinuation.setAuthenticationDetails(new
                AuthenticationDetails(email, pass, null));
        authenticationContinuation.continueTask();
    }

    @Override
    public void getMFACode(final MultiFactorAuthenticationContinuation continuation) {
        GLog.i("getMFACode.continuation(): " + continuation.toString());
    }

    @Override
    public void authenticationChallenge(final ChallengeContinuation continuation) {
        GLog.i("authenticationChallenge.getChallengeName(): " + continuation.getChallengeName());

        if("NEW_PASSWORD_REQUIRED".equals(continuation.getChallengeName())) {
        }
    }

    @Override
    public void onFailure(Exception exception) {
        townListener.onError(exception);
    }
};
mutablealligator commented 6 years ago

Hi @miguelguzmanconde,

Are you facing the issue in the latest SDK version? Can you provide us logs where it succeeds and fails? Did you modify the AWS Region between the retries?

snodnipper commented 6 years ago

I have also triggered this issue. I had some old tokens and I deleted the user via the cognito webpage. Essentially, I encountered com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException: User does not exist. (Service: AmazonCognitoIdentityProvider; Status Code: 400; Error Code: UserNotFoundException; Request ID: 9911881f....).

The error message was "User does not exist." - you will note that the previous catch statement clears the tokens with clearCachedTokens();. I added the clear cached tokens method and that resolved my issue - without the fix the user was stuck in a failure loop.

   } catch (final Exception e) {
       clearCachedTokens(); // <- added
       throw new CognitoInternalErrorException("Failed to authenticate user", e);
   } 

https://github.com/aws/aws-sdk-android/blob/1c26696d4e06f193f463d7d3575624aa29740bfe/aws-android-sdk-cognitoidentityprovider/src/main/java/com/amazonaws/mobileconnectors/cognitoidentityprovider/CognitoUser.java#L853

mutablealligator commented 6 years ago

Hi @miguelguzmanconde, Can you provide us the implementation of UserPoolManager is possible? @snodnipper, We will check and add the trigger accordingly. Thank you for the analysis.

drxeno02 commented 6 years ago

I am running into the same issue. This is new, it was working before. I updated the cognito library to v2.6.14. The error I am receiving is:

com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException: User does not exist. (Service: AmazonCognitoIdentityProvider; Status Code: 400; Error Code: UserNotFoundException; Request ID: 334a4da1-42a3-11e8-8072-11ccbb2a2c28)

I was trying to get user details using the "GetDetailsHandler". I successfully signed the user in, then I tried to get user details.

    private static void getUserDetails() {
        // set user
        mUser = mUserPool.getCurrentUser();

        GetDetailsHandler handler = new GetDetailsHandler() {
            @Override
            public void onSuccess(CognitoUserDetails cognitoUserDetails) {

            }

            @Override
            public void onFailure(Exception exception) {
                exception.printStackTrace();
                // get user details failed
                Log.e(TAG, exception.toString());
                if (!FrameworkUtils.checkIfNull(mDatabaseRegisterCompleteLister)) {
                    // set listener
                    mDatabaseRegisterCompleteLister.onFailure(exception);
                }
            }
        };
        mUser.getDetailsInBackground(handler);

mUser object is not null. It has all the correct information, e.g. context, secretHash, userId, pool, cognitoIdentityProviderclient, ect. What happened?

npalethorpe commented 6 years ago

Experiencing the same issue suddenly too. Its been working fine for months prior to today for me.

com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException: User does not exist. (Service: AmazonCognitoIdentityProvider; Status Code: 400; Error Code: UserNotFoundException; Request ID: 62156912-4958-11e8-b18b-b1ca6355ff7d)

I have updated to the latest SDK (2.6.18) and still no luck. It only appears to be occurring with certain credentials though - other users are having no issue authenticating. The iOS SDK has no problem authenticating with the same accounts.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 6 years ago

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.