CreateTokenWithIAM - Amazon IAM Identity Center
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

CreateTokenWithIAM

Creates and returns access and refresh tokens for clients and applications that are authenticated using IAM entities. The access token can be used to fetch short-term credentials for the assigned Amazon accounts or to access application APIs using bearer authentication.

Request Syntax

POST /token?aws_iam=t HTTP/1.1 Content-type: application/json { "assertion": "string", "clientId": "string", "code": "string", "grantType": "string", "redirectUri": "string", "refreshToken": "string", "requestedTokenType": "string", "scope": [ "string" ], "subjectToken": "string", "subjectTokenType": "string" }

URI Request Parameters

The request does not use any URI parameters.

Request Body

The request accepts the following data in JSON format.

assertion

Used only when calling this API for the JWT Bearer grant type. This value specifies the JSON Web Token (JWT) issued by a trusted token issuer. To authorize a trusted token issuer, configure the JWT Bearer GrantOptions for the application.

Type: String

Required: No

clientId

The unique identifier string for the client or application. This value is an application ARN that has OAuth grants configured.

Type: String

Required: Yes

code

Used only when calling this API for the Authorization Code grant type. This short-term code is used to identify this authorization request. The code is obtained through a redirect from IAM Identity Center to a redirect URI persisted in the Authorization Code GrantOptions for the application.

Type: String

Required: No

grantType

Supports the following OAuth grant types: Authorization Code, Refresh Token, JWT Bearer, and Token Exchange. Specify one of the following values, depending on the grant type that you want:

* Authorization Code - authorization_code

* Refresh Token - refresh_token

* JWT Bearer - urn:ietf:params:oauth:grant-type:jwt-bearer

* Token Exchange - urn:ietf:params:oauth:grant-type:token-exchange

Type: String

Required: Yes

redirectUri

Used only when calling this API for the Authorization Code grant type. This value specifies the location of the client or application that has registered to receive the authorization code.

Type: String

Required: No

refreshToken

Used only when calling this API for the Refresh Token grant type. This token is used to refresh short-term tokens, such as the access token, that might expire.

For more information about the features and limitations of the current IAM Identity Center OIDC implementation, see Considerations for Using this Guide in the IAM Identity Center OIDC API Reference.

Type: String

Required: No

requestedTokenType

Used only when calling this API for the Token Exchange grant type. This value specifies the type of token that the requester can receive. The following values are supported:

* Access Token - urn:ietf:params:oauth:token-type:access_token

* Refresh Token - urn:ietf:params:oauth:token-type:refresh_token

Type: String

Required: No

scope

The list of scopes for which authorization is requested. The access token that is issued is limited to the scopes that are granted. If the value is not specified, IAM Identity Center authorizes all scopes configured for the application, including the following default scopes: openid, aws, sts:identity_context.

Type: Array of strings

Required: No

subjectToken

Used only when calling this API for the Token Exchange grant type. This value specifies the subject of the exchange. The value of the subject token must be an access token issued by IAM Identity Center to a different client or application. The access token must have authorized scopes that indicate the requested application as a target audience.

Type: String

Required: No

subjectTokenType

Used only when calling this API for the Token Exchange grant type. This value specifies the type of token that is passed as the subject of the exchange. The following value is supported:

* Access Token - urn:ietf:params:oauth:token-type:access_token

Type: String

Required: No

Response Syntax

HTTP/1.1 200 Content-type: application/json { "accessToken": "string", "expiresIn": number, "idToken": "string", "issuedTokenType": "string", "refreshToken": "string", "scope": [ "string" ], "tokenType": "string" }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

accessToken

A bearer token to access Amazon accounts and applications assigned to a user.

Type: String

expiresIn

Indicates the time in seconds when an access token will expire.

Type: Integer

idToken

A JSON Web Token (JWT) that identifies the user associated with the issued access token.

Type: String

issuedTokenType

Indicates the type of tokens that are issued by IAM Identity Center. The following values are supported:

* Access Token - urn:ietf:params:oauth:token-type:access_token

* Refresh Token - urn:ietf:params:oauth:token-type:refresh_token

Type: String

refreshToken

A token that, if present, can be used to refresh a previously issued access token that might have expired.

For more information about the features and limitations of the current IAM Identity Center OIDC implementation, see Considerations for Using this Guide in the IAM Identity Center OIDC API Reference.

Type: String

scope

The list of scopes for which authorization is granted. The access token that is issued is limited to the scopes that are granted.

Type: Array of strings

tokenType

Used to notify the requester that the returned token is an access token. The supported token type is Bearer.

Type: String

Errors

For information about the errors that are common to all actions, see Common Errors.

AccessDeniedException

You do not have sufficient access to perform this action.

HTTP Status Code: 400

AuthorizationPendingException

Indicates that a request to authorize a client with an access user session token is pending.

HTTP Status Code: 400

ExpiredTokenException

Indicates that the token issued by the service is expired and is no longer valid.

HTTP Status Code: 400

InternalServerException

Indicates that an error from the service occurred while trying to process a request.

HTTP Status Code: 500

InvalidClientException

Indicates that the clientId or clientSecret in the request is invalid. For example, this can occur when a client sends an incorrect clientId or an expired clientSecret.

HTTP Status Code: 401

InvalidGrantException

Indicates that a request contains an invalid grant. This can occur if a client makes a CreateToken request with an invalid grant type.

HTTP Status Code: 400

InvalidRequestException

Indicates that something is wrong with the input to the request. For example, a required parameter might be missing or out of range.

HTTP Status Code: 400

InvalidRequestRegionException

Indicates that a token provided as input to the request was issued by and is only usable by calling IAM Identity Center endpoints in another region.

HTTP Status Code: 400

InvalidScopeException

Indicates that the scope provided in the request is invalid.

HTTP Status Code: 400

SlowDownException

Indicates that the client is making the request too frequently and is more than the service can handle.

HTTP Status Code: 400

UnauthorizedClientException

Indicates that the client is not currently authorized to make the request. This can happen when a clientId is not issued for a public client.

HTTP Status Code: 400

UnsupportedGrantTypeException

Indicates that the grant type in the request is not supported by the service.

HTTP Status Code: 400

See Also

For more information about using this API in one of the language-specific Amazon SDKs, see the following: