CreateToken
Creates and returns access and refresh tokens for clients that are authenticated using
client secrets. The access token can be used to fetch short-lived credentials for the assigned
AWS accounts or to access application APIs using bearer
authentication.
Request Syntax
POST /token HTTP/1.1
Content-type: application/json
{
"clientId": "string
",
"clientSecret": "string
",
"code": "string
",
"codeVerifier": "string
",
"deviceCode": "string
",
"grantType": "string
",
"redirectUri": "string
",
"refreshToken": "string
",
"scope": [ "string
" ]
}
URI Request Parameters
The request does not use any URI parameters.
Request Body
The request accepts the following data in JSON format.
- clientId
-
The unique identifier string for the client or application. This value comes from the result of the RegisterClient API.
Type: String
Required: Yes
- clientSecret
-
A secret string generated for the client. This value should come from the persisted result of the RegisterClient API.
Type: String
Required: Yes
- code
-
Used only when calling this API for the Authorization Code grant type. The short-lived code is used to identify this authorization request.
Type: String
Required: No
- codeVerifier
-
Used only when calling this API for the Authorization Code grant type. This value is generated by the client and presented to validate the original code challenge value the client passed at authorization time.
Type: String
Required: No
- deviceCode
-
Used only when calling this API for the Device Code grant type. This short-lived code is used to identify this authorization request. This comes from the result of the StartDeviceAuthorization API.
Type: String
Required: No
- grantType
-
Supports the following OAuth grant types: Authorization Code, Device Code, and Refresh Token. Specify one of the following values, depending on the grant type that you want:
* Authorization Code -
authorization_code
* Device Code -
urn:ietf:params:oauth:grant-type:device_code
* Refresh Token -
refresh_token
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-lived 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
- 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 this value is not specified, IAM Identity Center authorizes all scopes that are configured for the client during the call to RegisterClient.
Type: Array of strings
Required: No
Response Syntax
HTTP/1.1 200
Content-type: application/json
{
"accessToken": "string",
"expiresIn": number,
"idToken": "string",
"refreshToken": "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 AWS accounts and applications assigned to a user.
Type: String
- expiresIn
-
Indicates the time in seconds when an access token will expire.
Type: Integer
- idToken
-
The
idToken
is not implemented or supported. 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.A JSON Web Token (JWT) that identifies who is associated with the issued access 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
- tokenType
-
Used to notify the client 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
orclientSecret
in the request is invalid. For example, this can occur when a client sends an incorrectclientId
or an expiredclientSecret
.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
- 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 AWS SDKs, see the following: