createUserPoolClient method

Future<CreateUserPoolClientResponse> createUserPoolClient({
  1. required String clientName,
  2. required String userPoolId,
  3. int? accessTokenValidity,
  4. List<OAuthFlowType>? allowedOAuthFlows,
  5. bool? allowedOAuthFlowsUserPoolClient,
  6. List<String>? allowedOAuthScopes,
  7. AnalyticsConfigurationType? analyticsConfiguration,
  8. List<String>? callbackURLs,
  9. String? defaultRedirectURI,
  10. List<ExplicitAuthFlowsType>? explicitAuthFlows,
  11. bool? generateSecret,
  12. int? idTokenValidity,
  13. List<String>? logoutURLs,
  14. PreventUserExistenceErrorTypes? preventUserExistenceErrors,
  15. List<String>? readAttributes,
  16. int? refreshTokenValidity,
  17. List<String>? supportedIdentityProviders,
  18. TokenValidityUnitsType? tokenValidityUnits,
  19. List<String>? writeAttributes,
})

Creates the user pool client.

May throw InvalidParameterException. May throw ResourceNotFoundException. May throw TooManyRequestsException. May throw LimitExceededException. May throw NotAuthorizedException. May throw ScopeDoesNotExistException. May throw InvalidOAuthFlowException. May throw InternalErrorException.

Parameter clientName : The client name for the user pool client you would like to create.

Parameter userPoolId : The user pool ID for the user pool where you want to create a user pool client.

Parameter accessTokenValidity : The time limit, between 5 minutes and 1 day, after which the access token is no longer valid and cannot be used. This value will be overridden if you have entered a value in TokenValidityUnits.

Parameter allowedOAuthFlows : The allowed OAuth flows.

Set to code to initiate a code grant flow, which provides an authorization code as the response. This code can be exchanged for access tokens with the token endpoint.

Set to implicit to specify that the client should get the access token (and, optionally, ID token, based on scopes) directly.

Set to client_credentials to specify that the client should get the access token (and, optionally, ID token, based on scopes) from the token endpoint using a combination of client and client_secret.

Parameter allowedOAuthFlowsUserPoolClient : Set to true if the client is allowed to follow the OAuth protocol when interacting with Cognito user pools.

Parameter allowedOAuthScopes : The allowed OAuth scopes. Possible values provided by OAuth are: phone, email, openid, and profile. Possible values provided by AWS are: aws.cognito.signin.user.admin. Custom scopes created in Resource Servers are also supported.

Parameter analyticsConfiguration : The Amazon Pinpoint analytics configuration for collecting metrics for this user pool.

Parameter callbackURLs : A list of allowed redirect (callback) URLs for the identity providers.

A redirect URI must:

  • Be an absolute URI.
  • Be registered with the authorization server.
  • Not include a fragment component.
See OAuth 2.0 - Redirection Endpoint.

Amazon Cognito requires HTTPS over HTTP except for http://localhost for testing purposes only.

App callback URLs such as myapp://example are also supported.

Parameter defaultRedirectURI : The default redirect URI. Must be in the CallbackURLs list.

A redirect URI must:

  • Be an absolute URI.
  • Be registered with the authorization server.
  • Not include a fragment component.
See OAuth 2.0 - Redirection Endpoint.

Amazon Cognito requires HTTPS over HTTP except for http://localhost for testing purposes only.

App callback URLs such as myapp://example are also supported.

Parameter explicitAuthFlows : The authentication flows that are supported by the user pool clients. Flow names without the ALLOW_ prefix are deprecated in favor of new names with the ALLOW_ prefix. Note that values with ALLOW_ prefix cannot be used along with values without ALLOW_ prefix.

Valid values include:

  • ALLOW_ADMIN_USER_PASSWORD_AUTH: Enable admin based user password authentication flow ADMIN_USER_PASSWORD_AUTH. This setting replaces the ADMIN_NO_SRP_AUTH setting. With this authentication flow, Cognito receives the password in the request instead of using the SRP (Secure Remote Password protocol) protocol to verify passwords.
  • ALLOW_CUSTOM_AUTH: Enable Lambda trigger based authentication.
  • ALLOW_USER_PASSWORD_AUTH: Enable user password-based authentication. In this flow, Cognito receives the password in the request instead of using the SRP protocol to verify passwords.
  • ALLOW_USER_SRP_AUTH: Enable SRP based authentication.
  • ALLOW_REFRESH_TOKEN_AUTH: Enable authflow to refresh tokens.

Parameter generateSecret : Boolean to specify whether you want to generate a secret for the user pool client being created.

Parameter idTokenValidity : The time limit, between 5 minutes and 1 day, after which the ID token is no longer valid and cannot be used. This value will be overridden if you have entered a value in TokenValidityUnits.

Parameter logoutURLs : A list of allowed logout URLs for the identity providers.

Parameter preventUserExistenceErrors : Use this setting to choose which errors and responses are returned by Cognito APIs during authentication, account confirmation, and password recovery when the user does not exist in the user pool. When set to ENABLED and the user does not exist, authentication returns an error indicating either the username or password was incorrect, and account confirmation and password recovery return a response indicating a code was sent to a simulated destination. When set to LEGACY, those APIs will return a UserNotFoundException exception if the user does not exist in the user pool.

Valid values include:

  • ENABLED - This prevents user existence-related errors.
  • LEGACY - This represents the old behavior of Cognito where user existence related errors are not prevented.

Parameter readAttributes : The read attributes.

Parameter refreshTokenValidity : The time limit, in days, after which the refresh token is no longer valid and cannot be used.

Parameter supportedIdentityProviders : A list of provider names for the identity providers that are supported on this client. The following are supported: COGNITO, Facebook, Google and LoginWithAmazon.

Parameter tokenValidityUnits : The units in which the validity times are represented in. Default for RefreshToken is days, and default for ID and access tokens are hours.

Parameter writeAttributes : The user pool attributes that the app client can write to.

If your app client allows users to sign in through an identity provider, this array must include all attributes that are mapped to identity provider attributes. Amazon Cognito updates mapped attributes when users sign in to your application through an identity provider. If your app client lacks write access to a mapped attribute, Amazon Cognito throws an error when it attempts to update the attribute. For more information, see Specifying Identity Provider Attribute Mappings for Your User Pool.

Implementation

Future<CreateUserPoolClientResponse> createUserPoolClient({
  required String clientName,
  required String userPoolId,
  int? accessTokenValidity,
  List<OAuthFlowType>? allowedOAuthFlows,
  bool? allowedOAuthFlowsUserPoolClient,
  List<String>? allowedOAuthScopes,
  AnalyticsConfigurationType? analyticsConfiguration,
  List<String>? callbackURLs,
  String? defaultRedirectURI,
  List<ExplicitAuthFlowsType>? explicitAuthFlows,
  bool? generateSecret,
  int? idTokenValidity,
  List<String>? logoutURLs,
  PreventUserExistenceErrorTypes? preventUserExistenceErrors,
  List<String>? readAttributes,
  int? refreshTokenValidity,
  List<String>? supportedIdentityProviders,
  TokenValidityUnitsType? tokenValidityUnits,
  List<String>? writeAttributes,
}) async {
  ArgumentError.checkNotNull(clientName, 'clientName');
  _s.validateStringLength(
    'clientName',
    clientName,
    1,
    128,
    isRequired: true,
  );
  ArgumentError.checkNotNull(userPoolId, 'userPoolId');
  _s.validateStringLength(
    'userPoolId',
    userPoolId,
    1,
    55,
    isRequired: true,
  );
  _s.validateNumRange(
    'accessTokenValidity',
    accessTokenValidity,
    1,
    86400,
  );
  _s.validateStringLength(
    'defaultRedirectURI',
    defaultRedirectURI,
    1,
    1024,
  );
  _s.validateNumRange(
    'idTokenValidity',
    idTokenValidity,
    1,
    86400,
  );
  _s.validateNumRange(
    'refreshTokenValidity',
    refreshTokenValidity,
    0,
    315360000,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityProviderService.CreateUserPoolClient'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'ClientName': clientName,
      'UserPoolId': userPoolId,
      if (accessTokenValidity != null)
        'AccessTokenValidity': accessTokenValidity,
      if (allowedOAuthFlows != null)
        'AllowedOAuthFlows':
            allowedOAuthFlows.map((e) => e.toValue()).toList(),
      if (allowedOAuthFlowsUserPoolClient != null)
        'AllowedOAuthFlowsUserPoolClient': allowedOAuthFlowsUserPoolClient,
      if (allowedOAuthScopes != null)
        'AllowedOAuthScopes': allowedOAuthScopes,
      if (analyticsConfiguration != null)
        'AnalyticsConfiguration': analyticsConfiguration,
      if (callbackURLs != null) 'CallbackURLs': callbackURLs,
      if (defaultRedirectURI != null)
        'DefaultRedirectURI': defaultRedirectURI,
      if (explicitAuthFlows != null)
        'ExplicitAuthFlows':
            explicitAuthFlows.map((e) => e.toValue()).toList(),
      if (generateSecret != null) 'GenerateSecret': generateSecret,
      if (idTokenValidity != null) 'IdTokenValidity': idTokenValidity,
      if (logoutURLs != null) 'LogoutURLs': logoutURLs,
      if (preventUserExistenceErrors != null)
        'PreventUserExistenceErrors': preventUserExistenceErrors.toValue(),
      if (readAttributes != null) 'ReadAttributes': readAttributes,
      if (refreshTokenValidity != null)
        'RefreshTokenValidity': refreshTokenValidity,
      if (supportedIdentityProviders != null)
        'SupportedIdentityProviders': supportedIdentityProviders,
      if (tokenValidityUnits != null)
        'TokenValidityUnits': tokenValidityUnits,
      if (writeAttributes != null) 'WriteAttributes': writeAttributes,
    },
  );

  return CreateUserPoolClientResponse.fromJson(jsonResponse.body);
}