createUserPoolDomain method

Future<CreateUserPoolDomainResponse> createUserPoolDomain({
  1. required String domain,
  2. required String userPoolId,
  3. CustomDomainConfigType? customDomainConfig,
  4. int? managedLoginVersion,
  5. RoutingType? routing,
})

A user pool domain hosts managed login, an authorization server and web server for authentication in your application. This operation creates a new user pool prefix domain or custom domain and sets the managed login branding version. Set the branding version to 1 for hosted UI (classic) or 2 for managed login. When you choose a custom domain, you must provide an SSL certificate in the US East (N. Virginia) Amazon Web Services Region in your request.

Your prefix domain might take up to one minute to take effect. Your custom domain is online within five minutes, but it can take up to one hour to distribute your SSL certificate.

For more information about adding a custom domain to your user pool, see Configuring a user pool domain.

Learn more

May throw ConcurrentModificationException. May throw FeatureUnavailableInTierException. May throw InternalErrorException. May throw InvalidParameterException. May throw LimitExceededException. May throw NotAuthorizedException. May throw OperationNotEnabledException. May throw ResourceNotFoundException.

Parameter domain : The domain string. For custom domains, this is the fully-qualified domain name, such as auth.example.com. For prefix domains, this is the prefix alone, such as myprefix. A prefix value of myprefix for a user pool in the us-east-1 Region results in a domain of myprefix.auth.us-east-1.amazoncognito.com.

Parameter userPoolId : The ID of the user pool where you want to add a domain.

Parameter customDomainConfig : The configuration for a custom domain. Configures your domain with an Certificate Manager certificate in the us-east-1 Region.

Provide this parameter only if you want to use a custom domain for your user pool. Otherwise, you can omit this parameter and use a prefix domain instead.

When you create a custom domain, the passkey RP ID defaults to the custom domain. If you had a prefix domain active, this will cause passkey integration for your prefix domain to stop working due to a mismatch in RP ID. To keep the prefix domain passkey integration working, you can explicitly set RP ID to the prefix domain.

Parameter managedLoginVersion : The version of managed login branding that you want to apply to your domain. A value of 1 indicates hosted UI (classic) and a version of 2 indicates managed login.

Managed login requires that your user pool be configured for any feature plan other than Lite.

Parameter routing : The configuration of routing for requests to the domain for replicas of a replicated user pool. The routing configuration is currently only supported for custom domains.

Implementation

Future<CreateUserPoolDomainResponse> createUserPoolDomain({
  required String domain,
  required String userPoolId,
  CustomDomainConfigType? customDomainConfig,
  int? managedLoginVersion,
  RoutingType? routing,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityProviderService.CreateUserPoolDomain'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Domain': domain,
      'UserPoolId': userPoolId,
      if (customDomainConfig != null)
        'CustomDomainConfig': customDomainConfig,
      if (managedLoginVersion != null)
        'ManagedLoginVersion': managedLoginVersion,
      if (routing != null) 'Routing': routing,
    },
  );

  return CreateUserPoolDomainResponse.fromJson(jsonResponse.body);
}