createUserPoolClient method
- required String clientName,
- required String userPoolId,
- int? accessTokenValidity,
- List<
OAuthFlowType> ? allowedOAuthFlows, - bool? allowedOAuthFlowsUserPoolClient,
- List<
String> ? allowedOAuthScopes, - AnalyticsConfigurationType? analyticsConfiguration,
- int? authSessionValidity,
- List<
String> ? callbackURLs, - String? clientSecret,
- String? defaultRedirectURI,
- bool? enablePropagateAdditionalUserContextData,
- bool? enableTokenRevocation,
- List<
ExplicitAuthFlowsType> ? explicitAuthFlows, - bool? generateSecret,
- int? idTokenValidity,
- List<
String> ? logoutURLs, - PreventUserExistenceErrorTypes? preventUserExistenceErrors,
- List<
String> ? readAttributes, - RefreshTokenRotationType? refreshTokenRotation,
- int? refreshTokenValidity,
- List<
String> ? supportedIdentityProviders, - TokenValidityUnitsType? tokenValidityUnits,
- List<
String> ? writeAttributes,
Creates an app client in a user pool. This operation sets basic and advanced configuration options.
Unlike app clients created in the console, Amazon Cognito doesn't automatically assign a branding style to app clients that you configure with this API operation. Managed login and classic hosted UI pages aren't available for your client until after you apply a branding style.
Learn more
- Signing Amazon Web Services API Requests
- Using the Amazon Cognito user pools API and user pool endpoints
May throw FeatureUnavailableInTierException.
May throw InternalErrorException.
May throw InvalidOAuthFlowException.
May throw InvalidParameterException.
May throw LimitExceededException.
May throw NotAuthorizedException.
May throw OperationNotEnabledException.
May throw ResourceNotFoundException.
May throw ScopeDoesNotExistException.
May throw TooManyRequestsException.
Parameter clientName :
A friendly name for the app client that you want to create.
Parameter userPoolId :
The ID of the user pool where you want to create an app client.
Parameter accessTokenValidity :
The access token time limit. After this limit expires, your user can't use
their access token. To specify the time unit for
AccessTokenValidity as seconds,
minutes, hours, or days, set a
TokenValidityUnits value in your API request.
For example, when you set AccessTokenValidity to
10 and TokenValidityUnits to hours,
your user can authorize access with their access token for 10 hours.
The default time unit for AccessTokenValidity in an API
request is hours. Valid range is displayed below in seconds.
If you don't specify otherwise in the configuration of your app client, your access tokens are valid for one hour.
Parameter allowedOAuthFlows :
The OAuth grant types that you want your app client to generate for
clients in managed login authentication. To create an app client that
generates client credentials grants, you must add
client_credentials as the only allowed OAuth flow.
- code
-
Use a code grant flow, which provides an authorization code as the
response. This code can be exchanged for access tokens with the
/oauth2/tokenendpoint. - implicit
-
Issue the access token, and the ID token when scopes like
openidandprofileare requested, directly to your user. - client_credentials
-
Issue the access token from the
/oauth2/tokenendpoint directly to a non-person user, authorized by a combination of the client ID and client secret.
Parameter allowedOAuthFlowsUserPoolClient :
Set to true to use OAuth 2.0 authorization server features in
your app client.
This parameter must have a value of true before you can
configure the following features in your app client.
-
CallBackURLs: Callback URLs. -
LogoutURLs: Sign-out redirect URLs. -
AllowedOAuthScopes: OAuth 2.0 scopes. -
AllowedOAuthFlows: Support for authorization code, implicit, and client credentials OAuth 2.0 grants.
AllowedOAuthFlowsUserPoolClient to true in a
CreateUserPoolClient or UpdateUserPoolClient API
request. If you don't set a value for
AllowedOAuthFlowsUserPoolClient in a request with the CLI or
SDKs, it defaults to false. When false, only
SDK-based API sign-in is permitted.
Parameter allowedOAuthScopes :
The OAuth, OpenID Connect (OIDC), and custom scopes that you want to
permit your app client to authorize access with. Scopes govern access
control to user pool self-service API operations, user data from the
userInfo endpoint, and third-party APIs. Scope values include
phone, email, openid, and
profile. The aws.cognito.signin.user.admin scope
authorizes user self-service operations. Custom scopes with resource
servers authorize access to external APIs.
Parameter analyticsConfiguration :
The user pool analytics configuration for collecting metrics and sending
them to your Amazon Pinpoint campaign.
In Amazon Web Services Regions where Amazon Pinpoint isn't available, user pools might not have access to analytics or might be configurable with campaigns in the US East (N. Virginia) Region. For more information, see Using Amazon Pinpoint analytics.
Parameter authSessionValidity :
Amazon Cognito creates a session token for each API request in an
authentication flow. AuthSessionValidity is the duration, in
minutes, of that session token. Your user pool native user must respond to
each authentication challenge before the session expires.
Parameter callbackURLs :
A list of allowed redirect, or callback, URLs for managed login
authentication. These URLs are the paths where you want to send your
users' browsers after they complete authentication with managed login or a
third-party IdP. Typically, callback URLs are the home of an application
that uses OAuth or OIDC libraries to process authentication outcomes.
A redirect URI must meet the following requirements:
- Be an absolute URI.
-
Be registered with the authorization server. Amazon Cognito doesn't accept
authorization requests with
redirect_urivalues that aren't in the list ofCallbackURLsthat you provide in this parameter. - Not include a fragment component.
Amazon Cognito requires HTTPS over HTTP except for callback URLs to
http://localhost, http://127.0.0.1 and
http://[::1]. These callback URLs are for testing purposes
only. You can specify custom TCP ports for your callback URLs.
App callback URLs such as myapp://example are also supported.
Parameter clientSecret :
A custom client secret that you want to use for the app client. You cannot
specify both GenerateSecret as true and provide a ClientSecret value.
Parameter defaultRedirectURI :
The default redirect URI. In app clients with one assigned IdP, replaces
redirect_uri in authentication requests. Must be in the
CallbackURLs list.
Parameter enablePropagateAdditionalUserContextData :
When true, your application can include additional
UserContextData in authentication requests. This data
includes the IP address, and contributes to analysis by threat protection
features. For more information about propagation of user context data, see
Adding
session data to API requests. If you don’t include this parameter, you
can't send the source IP address to Amazon Cognito threat protection
features. You can only activate
EnablePropagateAdditionalUserContextData in an app client
that has a client secret.
Parameter enableTokenRevocation :
Activates or deactivates token
revocation in the target app client.
If you don't include this parameter, token revocation is automatically activated for the new user pool client.
Parameter explicitAuthFlows :
The authentication
flows that you want your user pool client to support. For each app
client in your user pool, you can sign in your users with any combination
of one or more flows, including with a user name and Secure Remote
Password (SRP), a user name and password, or a custom authentication
process that you define with Lambda functions.
The values for authentication flow options include the following.
-
ALLOW_USER_AUTH: Enable selection-based sign-in withUSER_AUTH. This setting covers username-password, secure remote password (SRP), passwordless, and passkey authentication. This authentiation flow can do username-password and SRP authentication without otherExplicitAuthFlowspermitting them. For example users can complete an SRP challenge throughUSER_AUTHwithout the flowUSER_SRP_AUTHbeing active for the app client. This flow doesn't includeCUSTOM_AUTH.To activate this setting, your user pool must be in the Essentials tier or higher.
-
ALLOW_ADMIN_USER_PASSWORD_AUTH: Enable admin based user password authentication flowADMIN_USER_PASSWORD_AUTH. This setting replaces theADMIN_NO_SRP_AUTHsetting. With this authentication flow, your app passes a user name and password to Amazon Cognito in the request, instead of using the Secure Remote Password (SRP) protocol to securely transmit the password. -
ALLOW_CUSTOM_AUTH: Enable Lambda trigger based authentication. -
ALLOW_USER_PASSWORD_AUTH: Enable user password-based authentication. In this flow, Amazon 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.
ADMIN_NO_SRP_AUTH, CUSTOM_AUTH_FLOW_ONLY, or
USER_PASSWORD_AUTH. You can't assign these legacy
ExplicitAuthFlows values to user pool clients at the same
time as values that begin with ALLOW_, like
ALLOW_USER_SRP_AUTH.
Parameter generateSecret :
When true, generates a client secret for the app client.
Client secrets are used with server-side and machine-to-machine
applications. Client secrets are automatically generated; you can't
specify a secret value. For more information, see App
client types.
Parameter idTokenValidity :
The ID token time limit. After this limit expires, your user can't use
their ID token. To specify the time unit for IdTokenValidity
as seconds, minutes, hours, or
days, set a TokenValidityUnits value in your API
request.
For example, when you set IdTokenValidity as 10
and TokenValidityUnits as hours, your user can
authenticate their session with their ID token for 10 hours.
The default time unit for IdTokenValidity in an API request
is hours. Valid range is displayed below in seconds.
If you don't specify otherwise in the configuration of your app client, your ID tokens are valid for one hour.
Parameter logoutURLs :
A list of allowed logout URLs for managed login authentication. When you
pass logout_uri and client_id parameters to
/logout, Amazon Cognito signs out your user and redirects
them to the logout URL. This parameter describes the URLs that you want to
be the permitted targets of logout_uri. A typical use of
these URLs is when a user selects "Sign out" and you redirect them to your
public homepage. For more information, see Logout
endpoint.
Parameter preventUserExistenceErrors :
When ENABLED, suppresses messages that might indicate a valid
user exists when someone attempts sign-in. This parameters sets your
preference for the errors and responses that you want Amazon Cognito APIs
to return during authentication, account confirmation, and password
recovery when the user doesn't exist in the user pool. When set to
ENABLED and the user doesn't exist, authentication returns an
error indicating either the username or password was incorrect. Account
confirmation and password recovery return a response indicating a code was
sent to a simulated destination. When set to LEGACY, those
APIs return a UserNotFoundException exception if the user
doesn't exist in the user pool.
Defaults to LEGACY.
Parameter readAttributes :
The list of user attributes that you want your app client to have read
access to. After your user authenticates in your app, their access token
authorizes them to read their own attribute value for any attribute in
this list.
When you don't specify the ReadAttributes for your app
client, your app can read the values of email_verified,
phone_number_verified, and the standard attributes of your
user pool. When your user pool app client has read access to these default
attributes, ReadAttributes doesn't return any information.
Amazon Cognito only populates ReadAttributes in the API
response if you have specified your own custom set of read attributes.
Parameter refreshTokenRotation :
The configuration of your app client for refresh token rotation. When
enabled, your app client issues new ID, access, and refresh tokens when
users renew their sessions with refresh tokens. When disabled, token
refresh issues only ID and access tokens.
Parameter refreshTokenValidity :
The refresh token time limit. After this limit expires, your user can't
use their refresh token. To specify the time unit for
RefreshTokenValidity as seconds,
minutes, hours, or days, set a
TokenValidityUnits value in your API request.
For example, when you set RefreshTokenValidity as
10 and TokenValidityUnits as days,
your user can refresh their session and retrieve new access and ID tokens
for 10 days.
The default time unit for RefreshTokenValidity in an API
request is days. You can't set RefreshTokenValidity to 0. If
you do, Amazon Cognito overrides the value with the default value of 30
days. Valid range is displayed below in seconds.
If you don't specify otherwise in the configuration of your app client, your refresh tokens are valid for 30 days.
Parameter supportedIdentityProviders :
A list of provider names for the identity providers (IdPs) that are
supported on this client. The following are supported:
COGNITO, Facebook, Google,
SignInWithApple, and LoginWithAmazon. You can
also specify the names that you configured for the SAML and OIDC IdPs in
your user pool, for example MySAMLIdP or
MyOIDCIdP.
This parameter sets the IdPs that managed
login will display on the login page for your app client. The removal
of COGNITO from this list doesn't prevent authentication
operations for local users with the user pools API in an Amazon Web
Services SDK. The only way to prevent SDK-based authentication is to block
access with a WAF
rule.
Parameter tokenValidityUnits :
The units that validity times are represented in. The default unit for
refresh tokens is days, and the default for ID and access tokens are
hours.
Parameter writeAttributes :
The list of user attributes that you want your app client to have write
access to. After your user authenticates in your app, their access token
authorizes them to set or modify their own attribute value for any
attribute in this list.
When you don't specify the WriteAttributes for your app
client, your app can write the values of the Standard attributes of your
user pool. When your user pool has write access to these default
attributes, WriteAttributes doesn't return any information.
Amazon Cognito only populates WriteAttributes in the API
response if you have specified your own custom set of write attributes.
If your app client allows users to sign in through an IdP, this array must include all attributes that you have mapped to IdP attributes. Amazon Cognito updates mapped attributes when users sign in to your application through an IdP. If your app client does not have write access to a mapped attribute, Amazon Cognito throws an error when it tries to update the attribute. For more information, see Specifying IdP 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,
int? authSessionValidity,
List<String>? callbackURLs,
String? clientSecret,
String? defaultRedirectURI,
bool? enablePropagateAdditionalUserContextData,
bool? enableTokenRevocation,
List<ExplicitAuthFlowsType>? explicitAuthFlows,
bool? generateSecret,
int? idTokenValidity,
List<String>? logoutURLs,
PreventUserExistenceErrorTypes? preventUserExistenceErrors,
List<String>? readAttributes,
RefreshTokenRotationType? refreshTokenRotation,
int? refreshTokenValidity,
List<String>? supportedIdentityProviders,
TokenValidityUnitsType? tokenValidityUnits,
List<String>? writeAttributes,
}) async {
_s.validateNumRange(
'accessTokenValidity',
accessTokenValidity,
1,
86400,
);
_s.validateNumRange(
'authSessionValidity',
authSessionValidity,
3,
15,
);
_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.value).toList(),
if (allowedOAuthFlowsUserPoolClient != null)
'AllowedOAuthFlowsUserPoolClient': allowedOAuthFlowsUserPoolClient,
if (allowedOAuthScopes != null)
'AllowedOAuthScopes': allowedOAuthScopes,
if (analyticsConfiguration != null)
'AnalyticsConfiguration': analyticsConfiguration,
if (authSessionValidity != null)
'AuthSessionValidity': authSessionValidity,
if (callbackURLs != null) 'CallbackURLs': callbackURLs,
if (clientSecret != null) 'ClientSecret': clientSecret,
if (defaultRedirectURI != null)
'DefaultRedirectURI': defaultRedirectURI,
if (enablePropagateAdditionalUserContextData != null)
'EnablePropagateAdditionalUserContextData':
enablePropagateAdditionalUserContextData,
if (enableTokenRevocation != null)
'EnableTokenRevocation': enableTokenRevocation,
if (explicitAuthFlows != null)
'ExplicitAuthFlows': explicitAuthFlows.map((e) => e.value).toList(),
if (generateSecret != null) 'GenerateSecret': generateSecret,
if (idTokenValidity != null) 'IdTokenValidity': idTokenValidity,
if (logoutURLs != null) 'LogoutURLs': logoutURLs,
if (preventUserExistenceErrors != null)
'PreventUserExistenceErrors': preventUserExistenceErrors.value,
if (readAttributes != null) 'ReadAttributes': readAttributes,
if (refreshTokenRotation != null)
'RefreshTokenRotation': refreshTokenRotation,
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);
}