Skip to content

change_password async

change_password(
    proposed_password: PasswordType,
    access_token: TokenModelType,
    *,
    config_overrides: Optional[AsyncCognitoIdentityProviderClientConfig] = None,
    previous_password: Optional[PasswordType] = None,
) -> ChangePasswordResponse

Changes the password for the currently signed-in user.

Authorize this action with a signed-in user's access token. It must include the scope aws.cognito.signin.user.admin.

Amazon Cognito doesn't evaluate Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you can't use IAM credentials to authorize requests, and you can't grant IAM permissions in policies. For more information about authorization models in Amazon Cognito, see Using the Amazon Cognito user pools API and user pool endpoints.

Parameters:

  • previous_password (Optional[PasswordType], default: None ) –

    The user's previous password. Required if the user has a password. If the user has no password and only signs in with passwordless authentication options, you can omit this parameter.

  • proposed_password (PasswordType) –

    A new password that you prompted the user to enter in your application.

  • access_token (TokenModelType) –

    A valid access token that Amazon Cognito issued to the user whose password you want to change.

Raises:

Source code in docs_src/capo_cognito_identity_provider/_services/async_cognito_identity_provider.py
async def change_password(
    self,
    proposed_password: "capo_cognito_identity_provider.types.password_type.PasswordType",
    access_token: "capo_cognito_identity_provider.types.token_model_type.TokenModelType",
    *,
    config_overrides: Optional[AsyncCognitoIdentityProviderClientConfig] = None,
    previous_password: Optional[
        "capo_cognito_identity_provider.types.password_type.PasswordType"
    ] = None,
) -> "capo_cognito_identity_provider.types.change_password_response.ChangePasswordResponse":
    """<p>Changes the password for the currently signed-in user.</p> <p>Authorize this action with a signed-in user's access token. It must include the scope <code>aws.cognito.signin.user.admin</code>.</p> <note> <p>Amazon Cognito doesn't evaluate Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you can't use IAM credentials to authorize requests, and you can't grant IAM permissions in policies. For more information about authorization models in Amazon Cognito, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pools-API-operations.html">Using the Amazon Cognito user pools API and user pool endpoints</a>.</p> </note>

    Args:
        previous_password: <p>The user's previous password. Required if the user has a password. If the user has no password and only signs in with passwordless authentication options, you can omit this parameter.</p>
        proposed_password: <p>A new password that you prompted the user to enter in your application.</p>
        access_token: <p>A valid access token that Amazon Cognito issued to the user whose password you want to change.</p>

    Raises:
        capo_cognito_identity_provider.errors.forbidden_exception.ForbiddenException: <p>This exception is thrown when WAF doesn't allow your request based on a web ACL that's associated with your user pool.</p>
        capo_cognito_identity_provider.errors.internal_error_exception.InternalErrorException: <p>This exception is thrown when Amazon Cognito encounters an internal error.</p>
        capo_cognito_identity_provider.errors.invalid_parameter_exception.InvalidParameterException: <p>This exception is thrown when the Amazon Cognito service encounters an invalid parameter.</p>
        capo_cognito_identity_provider.errors.invalid_password_exception.InvalidPasswordException: <p>This exception is thrown when Amazon Cognito encounters an invalid password.</p>
        capo_cognito_identity_provider.errors.limit_exceeded_exception.LimitExceededException: <p>This exception is thrown when a user exceeds the limit for a requested Amazon Web Services resource.</p>
        capo_cognito_identity_provider.errors.not_authorized_exception.NotAuthorizedException: <p>This exception is thrown when a user isn't authorized.</p>
        capo_cognito_identity_provider.errors.operation_not_enabled_exception.OperationNotEnabledException: <p>This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.</p>
        capo_cognito_identity_provider.errors.password_history_policy_violation_exception.PasswordHistoryPolicyViolationException: <p>The message returned when a user's new password matches a previous password and doesn't comply with the password-history policy.</p>
        capo_cognito_identity_provider.errors.password_reset_required_exception.PasswordResetRequiredException: <p>This exception is thrown when a password reset is required.</p>
        capo_cognito_identity_provider.errors.resource_not_found_exception.ResourceNotFoundException: <p>This exception is thrown when the Amazon Cognito service can't find the requested resource.</p>
        capo_cognito_identity_provider.errors.too_many_requests_exception.TooManyRequestsException: <p>This exception is thrown when the user has made too many requests for a given operation.</p>
        capo_cognito_identity_provider.errors.user_not_confirmed_exception.UserNotConfirmedException: <p>This exception is thrown when a user isn't confirmed successfully.</p>
        capo_cognito_identity_provider.errors.user_not_found_exception.UserNotFoundException: <p>This exception is thrown when a user isn't found.</p>
        capo_cognito_identity_provider.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_cognito_identity_provider.types.change_password_request.ChangePasswordRequest]",
    ) -> AsyncOperationResponse[
        "capo_cognito_identity_provider.types.change_password_response.ChangePasswordResponse"
    ]:
        import capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.change_password

        (
            output,
            http_response,
        ) = await capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.change_password.async_change_password(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_cognito_identity_provider.types.change_password_request.ChangePasswordRequest",
    ) -> dict[str, Any]:
        import capo_cognito_identity_provider.types.change_password_request

        return capo_cognito_identity_provider.types.change_password_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("ChangePassword", redact_input=_redact_input),
    )
    input_: capo_cognito_identity_provider.types.change_password_request.ChangePasswordRequest = {
        "proposed_password": proposed_password,
        "access_token": access_token,
    }
    if previous_password is not None:
        input_["previous_password"] = previous_password

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output