setUserPoolMfaConfig method

Future<SetUserPoolMfaConfigResponse> setUserPoolMfaConfig({
  1. required String userPoolId,
  2. EmailMfaConfigType? emailMfaConfiguration,
  3. UserPoolMfaType? mfaConfiguration,
  4. SmsMfaConfigType? smsMfaConfiguration,
  5. SoftwareTokenMfaConfigType? softwareTokenMfaConfiguration,
  6. WebAuthnConfigurationType? webAuthnConfiguration,
})

Sets user pool multi-factor authentication (MFA) and passkey configuration. For more information about user pool MFA, see Adding MFA. For more information about WebAuthn passkeys see Authentication flows.

If you have never used SMS text messages with Amazon Cognito or any other Amazon Web Services service, Amazon Simple Notification Service might place your account in the SMS sandbox. In sandbox mode , you can send messages only to verified phone numbers. After you test your app while in the sandbox environment, you can move out of the sandbox and into production. For more information, see SMS message settings for Amazon Cognito user pools in the Amazon Cognito Developer Guide.

May throw ConcurrentModificationException. May throw FeatureUnavailableInTierException. May throw InternalErrorException. May throw InvalidParameterException. May throw InvalidSmsRoleAccessPolicyException. May throw InvalidSmsRoleTrustRelationshipException. May throw NotAuthorizedException. May throw OperationNotEnabledException. May throw ResourceNotFoundException. May throw TooManyRequestsException.

Parameter userPoolId : The user pool ID.

Parameter emailMfaConfiguration : Sets configuration for user pool email message MFA and sign-in with one-time passwords (OTPs). Includes the subject and body of the email message template for sign-in and MFA messages. To activate this setting, your user pool must be in the Essentials tier or higher.

Parameter mfaConfiguration : Sets multi-factor authentication (MFA) to be on, off, or optional. When ON, all users must set up MFA before they can sign in. When OPTIONAL, your application must make a client-side determination of whether a user wants to register an MFA device. For user pools with adaptive authentication with threat protection, choose OPTIONAL.

When MfaConfiguration is OPTIONAL, managed login doesn't automatically prompt users to set up MFA. Amazon Cognito generates MFA prompts in API responses and in managed login for users who have chosen and configured a preferred MFA factor.

Parameter smsMfaConfiguration : Configures user pool SMS messages for MFA. Sets the message template and the SMS message sending configuration for Amazon SNS.

Parameter softwareTokenMfaConfiguration : Configures a user pool for time-based one-time password (TOTP) MFA. Enables or disables TOTP.

Parameter webAuthnConfiguration : The configuration of your user pool for passkey, or WebAuthn, authentication and registration. Includes relying-party configuration, user-verification requirements, and whether passkeys can satisfy MFA requirements.

Implementation

Future<SetUserPoolMfaConfigResponse> setUserPoolMfaConfig({
  required String userPoolId,
  EmailMfaConfigType? emailMfaConfiguration,
  UserPoolMfaType? mfaConfiguration,
  SmsMfaConfigType? smsMfaConfiguration,
  SoftwareTokenMfaConfigType? softwareTokenMfaConfiguration,
  WebAuthnConfigurationType? webAuthnConfiguration,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityProviderService.SetUserPoolMfaConfig'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'UserPoolId': userPoolId,
      if (emailMfaConfiguration != null)
        'EmailMfaConfiguration': emailMfaConfiguration,
      if (mfaConfiguration != null)
        'MfaConfiguration': mfaConfiguration.value,
      if (smsMfaConfiguration != null)
        'SmsMfaConfiguration': smsMfaConfiguration,
      if (softwareTokenMfaConfiguration != null)
        'SoftwareTokenMfaConfiguration': softwareTokenMfaConfiguration,
      if (webAuthnConfiguration != null)
        'WebAuthnConfiguration': webAuthnConfiguration,
    },
  );

  return SetUserPoolMfaConfigResponse.fromJson(jsonResponse.body);
}