Skip to content

admin_set_user_mfa_preference

admin_set_user_mfa_preference(
    username: UsernameType,
    user_pool_id: UserPoolIdType,
    *,
    config_overrides: Optional[CognitoIdentityProviderClientConfig] = None,
    sms_mfa_settings: Optional[SMSMfaSettingsType] = None,
    software_token_mfa_settings: Optional[SoftwareTokenMfaSettingsType] = None,
    email_mfa_settings: Optional[EmailMfaSettingsType] = None,
    web_authn_mfa_settings: Optional[WebAuthnMfaSettingsType] = None,
) -> AdminSetUserMFAPreferenceResponse

Sets the user's multi-factor authentication (MFA) preference, including which MFA options are activated, and if any are preferred. Only one factor can be set as preferred. The preferred MFA factor will be used to authenticate a user if multiple factors are activated. If multiple options are activated and no preference is set, a challenge to choose an MFA option will be returned during sign-in.

Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.

Learn more

Parameters:

  • sms_mfa_settings (Optional[SMSMfaSettingsType], default: None ) –

    User preferences for SMS message MFA. Activates or deactivates SMS MFA and sets it as the preferred MFA method when multiple methods are available.

  • software_token_mfa_settings (Optional[SoftwareTokenMfaSettingsType], default: None ) –

    User preferences for time-based one-time password (TOTP) MFA. Activates or deactivates TOTP MFA and sets it as the preferred MFA method when multiple methods are available.

  • email_mfa_settings (Optional[EmailMfaSettingsType], default: None ) –

    User preferences for email message MFA. Activates or deactivates email MFA and sets it as the preferred MFA method when multiple methods are available. To activate this setting, your user pool must be in the Essentials tier or higher.

  • web_authn_mfa_settings (Optional[WebAuthnMfaSettingsType], default: None ) –

    User preferences for passkey MFA. Activates or deactivates passkey MFA for the user. When activated, passkey authentication requires user verification, and passkey sign-in is available when MFA is required. To activate this setting, the FactorConfiguration of your user pool WebAuthnConfiguration must be MULTI_FACTOR_WITH_USER_VERIFICATION. To activate this setting, your user pool must be in the Essentials tier or higher.

  • username (UsernameType) –

    The name of the user that you want to query or modify. The value of this parameter is typically your user's username, but it can be any of their alias attributes. If username isn't an alias attribute in your user pool, this value must be the sub of a local user or the username of a user from a third-party IdP.

  • user_pool_id (UserPoolIdType) –

    The ID of the user pool where you want to set a user's MFA preferences.

Raises:

Source code in docs_src/capo_cognito_identity_provider/_services/cognito_identity_provider.py
def admin_set_user_mfa_preference(
    self,
    username: "capo_cognito_identity_provider.types.username_type.UsernameType",
    user_pool_id: "capo_cognito_identity_provider.types.user_pool_id_type.UserPoolIdType",
    *,
    config_overrides: Optional[CognitoIdentityProviderClientConfig] = None,
    sms_mfa_settings: Optional[
        "capo_cognito_identity_provider.types.sms_mfa_settings_type.SMSMfaSettingsType"
    ] = None,
    software_token_mfa_settings: Optional[
        "capo_cognito_identity_provider.types.software_token_mfa_settings_type.SoftwareTokenMfaSettingsType"
    ] = None,
    email_mfa_settings: Optional[
        "capo_cognito_identity_provider.types.email_mfa_settings_type.EmailMfaSettingsType"
    ] = None,
    web_authn_mfa_settings: Optional[
        "capo_cognito_identity_provider.types.web_authn_mfa_settings_type.WebAuthnMfaSettingsType"
    ] = None,
) -> "capo_cognito_identity_provider.types.admin_set_user_mfa_preference_response.AdminSetUserMFAPreferenceResponse":
    """<p>Sets the user's multi-factor authentication (MFA) preference, including which MFA options are activated, and if any are preferred. Only one factor can be set as preferred. The preferred MFA factor will be used to authenticate a user if multiple factors are activated. If multiple options are activated and no preference is set, a challenge to choose an MFA option will be returned during sign-in.</p> <note> <p>Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.</p> <p class="title"> <b>Learn more</b> </p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-signing.html">Signing Amazon Web Services API Requests</a> </p> </li> <li> <p> <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> </li> </ul> </note>

    Args:
        sms_mfa_settings: <p>User preferences for SMS message MFA. Activates or deactivates SMS MFA and sets it as the preferred MFA method when multiple methods are available.</p>
        software_token_mfa_settings: <p>User preferences for time-based one-time password (TOTP) MFA. Activates or deactivates TOTP MFA and sets it as the preferred MFA method when multiple methods are available.</p>
        email_mfa_settings: <p>User preferences for email message MFA. Activates or deactivates email MFA and sets it as the preferred MFA method when multiple methods are available. To activate this setting, your user pool must be in the <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/feature-plans-features-essentials.html"> Essentials tier</a> or higher.</p>
        web_authn_mfa_settings: <p>User preferences for passkey MFA. Activates or deactivates passkey MFA for the user. When activated, passkey authentication requires user verification, and passkey sign-in is available when MFA is required. To activate this setting, the <code>FactorConfiguration</code> of your user pool <code>WebAuthnConfiguration</code> must be <code>MULTI_FACTOR_WITH_USER_VERIFICATION</code>. To activate this setting, your user pool must be in the <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/feature-plans-features-essentials.html"> Essentials tier</a> or higher.</p>
        username: <p>The name of the user that you want to query or modify. The value of this parameter is typically your user's username, but it can be any of their alias attributes. If <code>username</code> isn't an alias attribute in your user pool, this value must be the <code>sub</code> of a local user or the username of a user from a third-party IdP.</p>
        user_pool_id: <p>The ID of the user pool where you want to set a user's MFA preferences.</p>

    Raises:
        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.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_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.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.
    """

    def _handler(
        req: "OperationRequest[capo_cognito_identity_provider.types.admin_set_user_mfa_preference_request.AdminSetUserMFAPreferenceRequest]",
    ) -> OperationResponse[
        "capo_cognito_identity_provider.types.admin_set_user_mfa_preference_response.AdminSetUserMFAPreferenceResponse"
    ]:
        import capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.admin_set_user_mfa_preference

        output, http_response = (
            capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.admin_set_user_mfa_preference.admin_set_user_mfa_preference(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

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

        return capo_cognito_identity_provider.types.admin_set_user_mfa_preference_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("AdminSetUserMFAPreference", redact_input=_redact_input),
    )
    input_: capo_cognito_identity_provider.types.admin_set_user_mfa_preference_request.AdminSetUserMFAPreferenceRequest = {
        "username": username,
        "user_pool_id": user_pool_id,
    }
    if sms_mfa_settings is not None:
        input_["sms_mfa_settings"] = sms_mfa_settings
    if software_token_mfa_settings is not None:
        input_["software_token_mfa_settings"] = software_token_mfa_settings
    if email_mfa_settings is not None:
        input_["email_mfa_settings"] = email_mfa_settings
    if web_authn_mfa_settings is not None:
        input_["web_authn_mfa_settings"] = web_authn_mfa_settings

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output