我的AWS控制台始终显示对用户禁用的SMS MFA STATUS,即使它在通过api登录期间要求提供MFA令牌。
遵循的步骤
AdminCreateUserRequest cognitoRequest = new AdminCreateUserRequest()
.withUserPoolId(cognitoConfig.getUserPoolId())<br>
// .withUserPoolId("us-east-1_vhXDAMWwN")<br>
.withUsername(signUpRequest.getUsername())<br>
.withUserAttributes(new AttributeType().withName(EMAIL).withValue(signUpRequest.getEmail()),<br>
new AttributeType().withName(NAME).withValue(signUpRequest.getName()),<br>
new AttributeType().withName(FAMILY_NAME).withValue(signUpRequest.getLastname()),<br>
new AttributeType().withName(PHONE_NUMBER).withValue(signUpRequest.getPhoneNumber()),<br>
new AttributeType().withName(EMAIL_VERIFIED).withValue(Boolean.TRUE.toString()))<br>
.withTemporaryPassword(cognitoConfig.getTempPassword())<br>
//uncomment this line to suppress welcome email and sms<br>
//.withMessageAction(MESSAGE_ACTION_SUPPRESS)<br>
.withDesiredDeliveryMediums(DeliveryMediumType.EMAIL, DeliveryMediumType.SMS)<br>
.withForceAliasCreation(Boolean.FALSE);<br>
UserSignUpResponse userSignUpResponse = new UserSignUpResponse();<br>
try {<br>
AdminCreateUserResult createUserResult = cognitoClient.adminCreateUser(cognitoRequest);<br>
UserType cognitoUser = createUserResult.getUser();<br>
if (cognitoUser != null && cognitoUser.getUserStatus().equals(FORCE_CHANGE_PASSWORD)) {<br>
//save / update user into rex db<br>
populateAndSaveUser(signUpRequest);<br>
userSignUpResponse.setName(cognitoUser.getUsername());<br>
userSignUpResponse.setResult(SUCCESS);<br>
userSignUpResponse.setStatus(FORCE_CHANGE_PASSWORD);<br>
}<br>
} catch (Exception ex) {<br>
throw new UserApiException(USER001, COGNITO_EXCEPTION, ex.toString());<br>
}<br>
code for setting mfa preference<br>
//add the new password to the params map<br>
Map<String,String> challengeParams = new HashMap<String,String>();<br>
challengeParams.put(USERNAME, username);<br>
challengeParams.put(PASSWORD, password);<br>
challengeParams.put(SMS_MFA_CODE, mfaCode);<br>
//populate the challenge response<br>
final AdminRespondToAuthChallengeRequest challengeRequest = new AdminRespondToAuthChallengeRequest();<br>
challengeRequest.withChallengeName(ChallengeNameType.SMS_MFA)<br>
.withClientId(cognitoConfig.getClientId())<br>
.withChallengeResponses(challengeParams)<br>
.withUserPoolId(cognitoConfig.getUserPoolId())<br>
.withSession(mySession);