

# CreateToken
<a name="API_CreateToken"></a>

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
<a name="API_CreateToken_RequestSyntax"></a>

```
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
<a name="API_CreateToken_RequestParameters"></a>

The request does not use any URI parameters.

## Request Body
<a name="API_CreateToken_RequestBody"></a>

The request accepts the following data in JSON format.

 ** [clientId](#API_CreateToken_RequestSyntax) **   <a name="singlesignon-CreateToken-request-clientId"></a>
The unique identifier string for the client or application. This value comes from the result of the [RegisterClient](API_RegisterClient.md) API.  
Type: String  
Required: Yes

 ** [clientSecret](#API_CreateToken_RequestSyntax) **   <a name="singlesignon-CreateToken-request-clientSecret"></a>
A secret string generated for the client. This value should come from the persisted result of the [RegisterClient](API_RegisterClient.md) API.  
Type: String  
Required: Yes

 ** [code](#API_CreateToken_RequestSyntax) **   <a name="singlesignon-CreateToken-request-code"></a>
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](#API_CreateToken_RequestSyntax) **   <a name="singlesignon-CreateToken-request-codeVerifier"></a>
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](#API_CreateToken_RequestSyntax) **   <a name="singlesignon-CreateToken-request-deviceCode"></a>
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_StartDeviceAuthorization.md) API.  
Type: String  
Required: No

 ** [grantType](#API_CreateToken_RequestSyntax) **   <a name="singlesignon-CreateToken-request-grantType"></a>
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:  
\$1 Authorization Code - `authorization_code`   
\$1 Device Code - `urn:ietf:params:oauth:grant-type:device_code`   
\$1 Refresh Token - `refresh_token`   
Type: String  
Required: Yes

 ** [redirectUri](#API_CreateToken_RequestSyntax) **   <a name="singlesignon-CreateToken-request-redirectUri"></a>
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](#API_CreateToken_RequestSyntax) **   <a name="singlesignon-CreateToken-request-refreshToken"></a>
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](https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/Welcome.html).  
Type: String  
Required: No

 ** [scope](#API_CreateToken_RequestSyntax) **   <a name="singlesignon-CreateToken-request-scope"></a>
The list of scopes for which authorization is requested. This parameter has no effect; the access token will always include all scopes configured during client registration.  
Type: Array of strings  
Required: No

## Response Syntax
<a name="API_CreateToken_ResponseSyntax"></a>

```
HTTP/1.1 200
Content-type: application/json

{
   "accessToken": "string",
   "expiresIn": number,
   "idToken": "string",
   "refreshToken": "string",
   "tokenType": "string"
}
```

## Response Elements
<a name="API_CreateToken_ResponseElements"></a>

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](#API_CreateToken_ResponseSyntax) **   <a name="singlesignon-CreateToken-response-accessToken"></a>
A bearer token to access AWS accounts and applications assigned to a user.  
Type: String

 ** [expiresIn](#API_CreateToken_ResponseSyntax) **   <a name="singlesignon-CreateToken-response-expiresIn"></a>
Indicates the time in seconds when an access token will expire.  
Type: Integer

 ** [idToken](#API_CreateToken_ResponseSyntax) **   <a name="singlesignon-CreateToken-response-idToken"></a>
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](https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/Welcome.html).  
A JSON Web Token (JWT) that identifies who is associated with the issued access token.   
Type: String

 ** [refreshToken](#API_CreateToken_ResponseSyntax) **   <a name="singlesignon-CreateToken-response-refreshToken"></a>
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](https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/Welcome.html).  
Type: String

 ** [tokenType](#API_CreateToken_ResponseSyntax) **   <a name="singlesignon-CreateToken-response-tokenType"></a>
Used to notify the client that the returned token is an access token. The supported token type is `Bearer`.  
Type: String

## Errors
<a name="API_CreateToken_Errors"></a>

For information about the errors that are common to all actions, see [Common Error Types](CommonErrors.md).

 ** AccessDeniedException **   
You do not have sufficient access to perform this action.    
 ** error **   
Single error code. For this exception the value will be `access_denied`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
HTTP Status Code: 400

 ** AuthorizationPendingException **   
Indicates that a request to authorize a client with an access user session token is pending.    
 ** error **   
Single error code. For this exception the value will be `authorization_pending`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
HTTP Status Code: 400

 ** ExpiredTokenException **   
Indicates that the token issued by the service is expired and is no longer valid.    
 ** error **   
Single error code. For this exception the value will be `expired_token`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
HTTP Status Code: 400

 ** InternalServerException **   
Indicates that an error from the service occurred while trying to process a request.    
 ** error **   
Single error code. For this exception the value will be `server_error`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
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`.    
 ** error **   
Single error code. For this exception the value will be `invalid_client`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
HTTP Status Code: 401

 ** InvalidGrantException **   
Indicates that a request contains an invalid grant. This can occur if a client makes a [CreateToken](#API_CreateToken) request with an invalid grant type.    
 ** error **   
Single error code. For this exception the value will be `invalid_grant`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
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.    
 ** error **   
Single error code. For this exception the value will be `invalid_request`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
HTTP Status Code: 400

 ** InvalidScopeException **   
Indicates that the scope provided in the request is invalid.    
 ** error **   
Single error code. For this exception the value will be `invalid_scope`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
HTTP Status Code: 400

 ** SlowDownException **   
Indicates that the client is making the request too frequently and is more than the service can handle.     
 ** error **   
Single error code. For this exception the value will be `slow_down`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
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.    
 ** error **   
Single error code. For this exception the value will be `unauthorized_client`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
HTTP Status Code: 400

 ** UnsupportedGrantTypeException **   
Indicates that the grant type in the request is not supported by the service.    
 ** error **   
Single error code. For this exception the value will be `unsupported_grant_type`.  
 ** error\$1description **   
Human-readable text providing additional information, used to assist the client developer in understanding the error that occurred.
HTTP Status Code: 400

## See Also
<a name="API_CreateToken_SeeAlso"></a>

For more information about using this API in one of the language-specific AWS SDKs, see the following:
+  [AWS Command Line Interface V2](https://docs.aws.amazon.com/goto/cli2/sso-oidc-2019-06-10/CreateToken) 
+  [AWS SDK for .NET V4](https://docs.aws.amazon.com/goto/DotNetSDKV4/sso-oidc-2019-06-10/CreateToken) 
+  [AWS SDK for C\$1\$1](https://docs.aws.amazon.com/goto/SdkForCpp/sso-oidc-2019-06-10/CreateToken) 
+  [AWS SDK for Go v2](https://docs.aws.amazon.com/goto/SdkForGoV2/sso-oidc-2019-06-10/CreateToken) 
+  [AWS SDK for Java V2](https://docs.aws.amazon.com/goto/SdkForJavaV2/sso-oidc-2019-06-10/CreateToken) 
+  [AWS SDK for JavaScript V3](https://docs.aws.amazon.com/goto/SdkForJavaScriptV3/sso-oidc-2019-06-10/CreateToken) 
+  [AWS SDK for Kotlin](https://docs.aws.amazon.com/goto/SdkForKotlin/sso-oidc-2019-06-10/CreateToken) 
+  [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/sso-oidc-2019-06-10/CreateToken) 
+  [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/sso-oidc-2019-06-10/CreateToken) 
+  [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/sso-oidc-2019-06-10/CreateToken) 