sendNewPasswordRequiredAnswer method
This is used by the user once he has the responses to the NEW_PASSWORD_REQUIRED challenge.
Its allow set a new user password and optionally set new user attributes. Attributes can be send in the requiredAttributes map where a map key is an attribute name and a map value is an attribute value.
Implementation
Future<CognitoUserSession?> sendNewPasswordRequiredAnswer(String newPassword,
[Map<String, String>? requiredAttributes]) async {
final challengeResponses = {
'USERNAME': username,
'NEW_PASSWORD': newPassword,
};
if (requiredAttributes != null && requiredAttributes.isNotEmpty) {
requiredAttributes.forEach((key, value) {
challengeResponses['userAttributes.$key'] = value;
});
}
final authenticationHelper =
AuthenticationHelper(pool.getUserPoolId().split('_')[1]);
await getCachedDeviceKeyAndPassword();
if (_deviceKey != null) {
challengeResponses['DEVICE_KEY'] = _deviceKey;
}
if (_clientSecretHash != null) {
challengeResponses['SECRET_HASH'] = _clientSecretHash;
}
final paramsReq = {
'ChallengeName': 'NEW_PASSWORD_REQUIRED',
'ChallengeResponses': challengeResponses,
'ClientId': pool.getClientId(),
'Session': _session,
};
if (getUserContextData() != null) {
paramsReq['UserContextData'] = getUserContextData();
}
final data = await client!.request('RespondToAuthChallenge',
await _analyticsMetadataParamsDecorator.call(paramsReq));
return _authenticateUserInternal(data, authenticationHelper);
}