createUserPool method

Future<CreateUserPoolResponse> createUserPool({
  1. required String poolName,
  2. AccountRecoverySettingType? accountRecoverySetting,
  3. AdminCreateUserConfigType? adminCreateUserConfig,
  4. List<AliasAttributeType>? aliasAttributes,
  5. List<VerifiedAttributeType>? autoVerifiedAttributes,
  6. DeviceConfigurationType? deviceConfiguration,
  7. EmailConfigurationType? emailConfiguration,
  8. String? emailVerificationMessage,
  9. String? emailVerificationSubject,
  10. LambdaConfigType? lambdaConfig,
  11. UserPoolMfaType? mfaConfiguration,
  12. UserPoolPolicyType? policies,
  13. List<SchemaAttributeType>? schema,
  14. String? smsAuthenticationMessage,
  15. SmsConfigurationType? smsConfiguration,
  16. String? smsVerificationMessage,
  17. UserPoolAddOnsType? userPoolAddOns,
  18. Map<String, String>? userPoolTags,
  19. List<UsernameAttributeType>? usernameAttributes,
  20. UsernameConfigurationType? usernameConfiguration,
  21. VerificationMessageTemplateType? verificationMessageTemplate,
})

Creates a new Amazon Cognito user pool and sets the password policy for the pool.

May throw InvalidParameterException. May throw TooManyRequestsException. May throw LimitExceededException. May throw InvalidSmsRoleAccessPolicyException. May throw InvalidSmsRoleTrustRelationshipException. May throw InvalidEmailRoleAccessPolicyException. May throw NotAuthorizedException. May throw UserPoolTaggingException. May throw InternalErrorException.

Parameter poolName : A string used to name the user pool.

Parameter accountRecoverySetting : Use this setting to define which verified available method a user can use to recover their password when they call ForgotPassword. It allows you to define a preferred method when a user has more than one method available. With this setting, SMS does not qualify for a valid password recovery mechanism if the user also has SMS MFA enabled. In the absence of this setting, Cognito uses the legacy behavior to determine the recovery method where SMS is preferred over email.

Parameter adminCreateUserConfig : The configuration for AdminCreateUser requests.

Parameter aliasAttributes : Attributes supported as an alias for this user pool. Possible values: phone_number, email, or preferred_username.

Parameter autoVerifiedAttributes : The attributes to be auto-verified. Possible values: email, phone_number.

Parameter deviceConfiguration : The device configuration.

Parameter emailConfiguration : The email configuration.

Parameter emailVerificationMessage : A string representing the email verification message. EmailVerificationMessage is allowed only if EmailSendingAccount is DEVELOPER.

Parameter emailVerificationSubject : A string representing the email verification subject. EmailVerificationSubject is allowed only if EmailSendingAccount is DEVELOPER.

Parameter lambdaConfig : The Lambda trigger configuration information for the new user pool.

For more information on using the Lambda API to add permission, see AddPermission .

For adding permission using the AWS CLI, see add-permission .

Parameter mfaConfiguration : Specifies MFA configuration details.

Parameter policies : The policies associated with the new user pool.

Parameter schema : An array of schema attributes for the new user pool. These attributes can be standard or custom attributes.

Parameter smsAuthenticationMessage : A string representing the SMS authentication message.

Parameter smsConfiguration : The SMS configuration.

Parameter smsVerificationMessage : A string representing the SMS verification message.

Parameter userPoolAddOns : Used to enable advanced security risk detection. Set the key AdvancedSecurityMode to the value "AUDIT".

Parameter userPoolTags : The tag keys and values to assign to the user pool. A tag is a label that you can use to categorize and manage user pools in different ways, such as by purpose, owner, environment, or other criteria.

Parameter usernameAttributes : Specifies whether email addresses or phone numbers can be specified as usernames when a user signs up.

Parameter usernameConfiguration : You can choose to set case sensitivity on the username input for the selected sign-in option. For example, when this is set to False, users will be able to sign in using either "username" or "Username". This configuration is immutable once it has been set. For more information, see UsernameConfigurationType.

Parameter verificationMessageTemplate : The template for the verification message that the user sees when the app requests permission to access the user's information.

Implementation

Future<CreateUserPoolResponse> createUserPool({
  required String poolName,
  AccountRecoverySettingType? accountRecoverySetting,
  AdminCreateUserConfigType? adminCreateUserConfig,
  List<AliasAttributeType>? aliasAttributes,
  List<VerifiedAttributeType>? autoVerifiedAttributes,
  DeviceConfigurationType? deviceConfiguration,
  EmailConfigurationType? emailConfiguration,
  String? emailVerificationMessage,
  String? emailVerificationSubject,
  LambdaConfigType? lambdaConfig,
  UserPoolMfaType? mfaConfiguration,
  UserPoolPolicyType? policies,
  List<SchemaAttributeType>? schema,
  String? smsAuthenticationMessage,
  SmsConfigurationType? smsConfiguration,
  String? smsVerificationMessage,
  UserPoolAddOnsType? userPoolAddOns,
  Map<String, String>? userPoolTags,
  List<UsernameAttributeType>? usernameAttributes,
  UsernameConfigurationType? usernameConfiguration,
  VerificationMessageTemplateType? verificationMessageTemplate,
}) async {
  ArgumentError.checkNotNull(poolName, 'poolName');
  _s.validateStringLength(
    'poolName',
    poolName,
    1,
    128,
    isRequired: true,
  );
  _s.validateStringLength(
    'emailVerificationMessage',
    emailVerificationMessage,
    6,
    20000,
  );
  _s.validateStringLength(
    'emailVerificationSubject',
    emailVerificationSubject,
    1,
    140,
  );
  _s.validateStringLength(
    'smsAuthenticationMessage',
    smsAuthenticationMessage,
    6,
    140,
  );
  _s.validateStringLength(
    'smsVerificationMessage',
    smsVerificationMessage,
    6,
    140,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityProviderService.CreateUserPool'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'PoolName': poolName,
      if (accountRecoverySetting != null)
        'AccountRecoverySetting': accountRecoverySetting,
      if (adminCreateUserConfig != null)
        'AdminCreateUserConfig': adminCreateUserConfig,
      if (aliasAttributes != null)
        'AliasAttributes': aliasAttributes.map((e) => e.toValue()).toList(),
      if (autoVerifiedAttributes != null)
        'AutoVerifiedAttributes':
            autoVerifiedAttributes.map((e) => e.toValue()).toList(),
      if (deviceConfiguration != null)
        'DeviceConfiguration': deviceConfiguration,
      if (emailConfiguration != null)
        'EmailConfiguration': emailConfiguration,
      if (emailVerificationMessage != null)
        'EmailVerificationMessage': emailVerificationMessage,
      if (emailVerificationSubject != null)
        'EmailVerificationSubject': emailVerificationSubject,
      if (lambdaConfig != null) 'LambdaConfig': lambdaConfig,
      if (mfaConfiguration != null)
        'MfaConfiguration': mfaConfiguration.toValue(),
      if (policies != null) 'Policies': policies,
      if (schema != null) 'Schema': schema,
      if (smsAuthenticationMessage != null)
        'SmsAuthenticationMessage': smsAuthenticationMessage,
      if (smsConfiguration != null) 'SmsConfiguration': smsConfiguration,
      if (smsVerificationMessage != null)
        'SmsVerificationMessage': smsVerificationMessage,
      if (userPoolAddOns != null) 'UserPoolAddOns': userPoolAddOns,
      if (userPoolTags != null) 'UserPoolTags': userPoolTags,
      if (usernameAttributes != null)
        'UsernameAttributes':
            usernameAttributes.map((e) => e.toValue()).toList(),
      if (usernameConfiguration != null)
        'UsernameConfiguration': usernameConfiguration,
      if (verificationMessageTemplate != null)
        'VerificationMessageTemplate': verificationMessageTemplate,
    },
  );

  return CreateUserPoolResponse.fromJson(jsonResponse.body);
}