How to change User Status FORCE_CHANGE_PASSWORD?

前端 未结 12 1878
我在风中等你
我在风中等你 2020-12-07 08:15

Using AWS Cognito, I want to create dummy users for testing purposes.

I then use the AWS Console to create such user, but the user has its status s

12条回答
  •  囚心锁ツ
    2020-12-07 08:29

    For Java SDK, assuming your Cognito client is setup and you have your user in the FORCE_CHANGE_PASSWORD state you can do the following to get your user CONFIRMED... and then auth'd as normal.

    AdminCreateUserResult createUserResult = COGNITO_CLIENT.adminCreateUser(createUserRequest());
    
    AdminInitiateAuthResult authResult = COGNITO_CLIENT.adminInitiateAuth(authUserRequest());
    
    
    Map challengeResponses = new HashMap<>();
    challengeResponses.put("USERNAME", USERNAME);
    challengeResponses.put("NEW_PASSWORD", PASSWORD);
    RespondToAuthChallengeRequest respondToAuthChallengeRequest = new RespondToAuthChallengeRequest()
          .withChallengeName("NEW_PASSWORD_REQUIRED")
          .withClientId(CLIENT_ID)
          .withChallengeResponses(challengeResponses)
          .withSession(authResult.getSession());
    
    COGNITO_CLIENT.respondToAuthChallenge(respondToAuthChallengeRequest);
    

    Hope it helps with those integration tests (Sorry about the formatting)

提交回复
热议问题