adminSetUserPassword method

Future<void> adminSetUserPassword({
  1. required String password,
  2. required String userPoolId,
  3. required String username,
  4. bool? permanent,
})

Sets the specified user's password in a user pool as an administrator. Works on any user.

The password can be temporary or permanent. If it is temporary, the user status will be placed into the FORCE_CHANGE_PASSWORD state. When the user next tries to sign in, the InitiateAuth/AdminInitiateAuth response will contain the NEW_PASSWORD_REQUIRED challenge. If the user does not sign in before it expires, the user will not be able to sign in and their password will need to be reset by an administrator.

Once the user has set a new password, or the password is permanent, the user status will be set to Confirmed.

May throw ResourceNotFoundException. May throw NotAuthorizedException. May throw UserNotFoundException. May throw InternalErrorException. May throw TooManyRequestsException. May throw InvalidParameterException. May throw InvalidPasswordException.

Parameter password : The password for the user.

Parameter userPoolId : The user pool ID for the user pool where you want to set the user's password.

Parameter username : The user name of the user whose password you wish to set.

Parameter permanent : True if the password is permanent, False if it is temporary.

Implementation

Future<void> adminSetUserPassword({
  required String password,
  required String userPoolId,
  required String username,
  bool? permanent,
}) async {
  ArgumentError.checkNotNull(password, 'password');
  _s.validateStringLength(
    'password',
    password,
    6,
    256,
    isRequired: true,
  );
  ArgumentError.checkNotNull(userPoolId, 'userPoolId');
  _s.validateStringLength(
    'userPoolId',
    userPoolId,
    1,
    55,
    isRequired: true,
  );
  ArgumentError.checkNotNull(username, 'username');
  _s.validateStringLength(
    'username',
    username,
    1,
    128,
    isRequired: true,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityProviderService.AdminSetUserPassword'
  };
  await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Password': password,
      'UserPoolId': userPoolId,
      'Username': username,
      if (permanent != null) 'Permanent': permanent,
    },
  );
}