CognitoIdentityProvider / Client / get_client_token
get_client_token¶
- CognitoIdentityProvider.Client.get_client_token(**kwargs)¶
Issues an access token for machine-to-machine (M2M) authorization. Your app client provides its client ID and secret, and receives an access token that authorizes requests to your resource servers.
GetClientTokenprovides the same functionality as the OAuth2 client-credentials grant; both authorize an application rather than a user.To use this operation, you must configure the app client with a client secret and enable the
ALLOW_CLIENT_TOKEN_AUTHauthentication flow. TheALLOW_CLIENT_TOKEN_AUTHflow is mutually exclusive with user authentication flows. It must be the only authentication flow that you configure for the app client. For more information, see Scopes, M2M, and resource servers.Note
Amazon Cognito doesn’t evaluate Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you can’t use IAM credentials to authorize requests, and you can’t grant IAM permissions in policies. For more information about authorization models in Amazon Cognito, see Using the Amazon Cognito user pools API and user pool endpoints.
See also: AWS API Documentation
Request Syntax
response = client.get_client_token( ClientId='string', Secret='string', Scopes=[ 'string', ], ClientMetadata={ 'string': 'string' } )
- Parameters:
ClientId (string) –
[REQUIRED]
The ID of the app client that requests the access token. The app client must have a client secret and the
ALLOW_CLIENT_TOKEN_AUTHauthentication flow.Secret (string) –
[REQUIRED]
An active secret for the app client.
Scopes (list) –
The custom scopes to authorize in the access token, in the format
resource-server-identifier/scope-name. Each scope must belong to a resource server in your user pool. If you don’t specify any scopes, Amazon Cognito authorizes the scopes that are configured for the app client.(string) –
ClientMetadata (dict) –
A map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers. You create custom workflows by assigning Lambda functions to user pool triggers.
When Amazon Cognito invokes any of these functions, it passes a JSON payload, which the function receives as input. This payload contains a
clientMetadataattribute that provides the data that you assigned to the ClientMetadata parameter in your request. In your function code, you can process theclientMetadatavalue to enhance your workflow for your specific needs.To review the Lambda trigger types that Amazon Cognito invokes at runtime with API requests, see Connecting API actions to Lambda triggers in the Amazon Cognito Developer Guide.
Note
When you use the
ClientMetadataparameter, note that Amazon Cognito won’t do the following:Store the
ClientMetadatavalue. This data is available only to Lambda triggers that are assigned to a user pool to support custom workflows. If your user pool configuration doesn’t include triggers, theClientMetadataparameter serves no purpose.Validate the
ClientMetadatavalue.Encrypt the
ClientMetadatavalue. Don’t send sensitive information in this parameter.
(string) –
(string) –
- Return type:
dict
- Returns:
Response Syntax
{ 'ClientAuthenticationResult': { 'AccessToken': 'string', 'ExpiresIn': 123, 'TokenType': 'string' } }
Response Structure
(dict) –
ClientAuthenticationResult (dict) –
The access token that Amazon Cognito issues for the app client, and its metadata.
AccessToken (string) –
The access token for the requested app client. Present this token to a resource server to authorize a request, using the scopes granted in the token.
ExpiresIn (integer) –
The number of seconds until the access token expires.
TokenType (string) –
The type of the token. For example,
Bearer.
Exceptions
CognitoIdentityProvider.Client.exceptions.InvalidParameterExceptionCognitoIdentityProvider.Client.exceptions.ResourceNotFoundExceptionCognitoIdentityProvider.Client.exceptions.NotAuthorizedExceptionCognitoIdentityProvider.Client.exceptions.TooManyRequestsExceptionCognitoIdentityProvider.Client.exceptions.InternalErrorExceptionCognitoIdentityProvider.Client.exceptions.OperationNotEnabledExceptionCognitoIdentityProvider.Client.exceptions.ForbiddenException