

# GetOAuthToken

Retrieves an OAuth access token from a credential provider. The broker authenticates to the provider's authorization server with the client credentials configured on the provider, obtains a token, and returns it — so your workload never handles the provider's client secret.

The broker caches the access token it obtains until that token expires, or for up to one hour when the token's own lifetime is longer than an hour. A call made while a cached token is still valid returns that token instead of requesting a new one; set `forceAuthentication` to bypass the cache and force a fresh request to the authorization server.

The grant type you name must be one the provider allows. CLIENT\_CREDENTIALS returns a token representing the workload itself; TOKEN\_EXCHANGE returns a token that preserves the identity of the caller the workload is acting for; AUTHORIZATION\_CODE returns a token representing an end user who granted consent, and requires a consent session that user has already completed, named in `sessionUri`; JWT\_AUTHORIZATION\_GRANT presents a signed JWT as the grant, so no client secret is sent on the token request. Of the supported vendors, only Microsoft Entra ID accepts this grant today: Entra implements on-behalf-of delegation with the RFC 7523 JWT bearer grant (`urn:ietf:params:oauth:grant-type:jwt-bearer`), where other authorization servers use RFC 8693 token exchange.

## Request Syntax
<a name="API_GetOAuthToken_RequestSyntax"></a>

```
POST /oauth2/token HTTP/1.1
Content-type: application/json

{
   "audiences": [ "{{string}}" ],
   "credentialProviderArn": "{{string}}",
   "customParameters": { 
      "{{string}}" : "{{string}}" 
   },
   "forceAuthentication": {{boolean}},
   "grantType": "{{string}}",
   "resources": [ "{{string}}" ],
   "scopes": [ "{{string}}" ],
   "sessionUri": "{{string}}"
}
```

## URI Request Parameters
<a name="API_GetOAuthToken_RequestParameters"></a>

The request does not use any URI parameters.

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

The request accepts the following data in JSON format.

 ** [audiences](#API_GetOAuthToken_RequestSyntax) **   <a name="credentialbroker-GetOAuthToken-request-audiences"></a>
Audience values (RFC 8693) naming the intended recipients of this token. Omit unless the authorization server requires them.  
Type: Array of strings  
Array Members: Minimum number of 0 items. Maximum number of 10 items.  
Length Constraints: Minimum length of 1. Maximum length of 2048.  
Required: No

 ** [credentialProviderArn](#API_GetOAuthToken_RequestSyntax) **   <a name="credentialbroker-GetOAuthToken-request-credentialProviderArn"></a>
Amazon Resource Name of the credential provider to obtain the token from. The provider must be an OAuth provider and must be READY.  
Type: String  
Pattern: `arn:(aws|aws-us-gov|aws-cn|aws-iso|aws-iso-b|aws-iso-e|aws-iso-f|aws-eusc):credentialbroker:[a-z0-9-]{1,64}:[0-9]{12}:credentialproviderpool/[a-z0-9]{1,64}/credentialprovider/[a-z0-9]{1,64}`   
Required: Yes

 ** [customParameters](#API_GetOAuthToken_RequestSyntax) **   <a name="credentialbroker-GetOAuthToken-request-customParameters"></a>
Extra parameters to include in the request to the authorization server, for vendor extensions. Added to the standard OAuth parameters; they never override them.  
Type: String to string map  
Map Entries: Minimum number of 0 items. Maximum number of 20 items.  
Key Length Constraints: Minimum length of 1. Maximum length of 256.  
Key Pattern: `[a-zA-Z0-9_.-]+`   
Value Length Constraints: Minimum length of 1. Maximum length of 2048.  
Required: No

 ** [forceAuthentication](#API_GetOAuthToken_RequestSyntax) **   <a name="credentialbroker-GetOAuthToken-request-forceAuthentication"></a>
Request a new token from the authorization server even when the broker already holds a valid one for this provider. Defaults to false, which returns the held token when one is available.  
Type: Boolean  
Required: No

 ** [grantType](#API_GetOAuthToken_RequestSyntax) **   <a name="credentialbroker-GetOAuthToken-request-grantType"></a>
How the token is obtained. Must be one of the grant types the provider allows; a grant the provider does not allow is rejected.  
Type: String  
Valid Values: `CLIENT_CREDENTIALS | TOKEN_EXCHANGE | JWT_AUTHORIZATION_GRANT | AUTHORIZATION_CODE`   
Required: Yes

 ** [resources](#API_GetOAuthToken_RequestSyntax) **   <a name="credentialbroker-GetOAuthToken-request-resources"></a>
Resource indicators (RFC 8707) naming the APIs this token is for. Omit unless the authorization server requires them.  
Type: Array of strings  
Array Members: Minimum number of 0 items. Maximum number of 10 items.  
Length Constraints: Minimum length of 1. Maximum length of 2048.  
Required: No

 ** [scopes](#API_GetOAuthToken_RequestSyntax) **   <a name="credentialbroker-GetOAuthToken-request-scopes"></a>
The OAuth scopes to request from the authorization server.  
Type: Array of strings  
Array Members: Minimum number of 1 item. Maximum number of 20 items.  
Length Constraints: Minimum length of 1. Maximum length of 256.  
Required: No

 ** [sessionUri](#API_GetOAuthToken_RequestSyntax) **   <a name="credentialbroker-GetOAuthToken-request-sessionUri"></a>
Return the token obtained for a consent session that a user has already completed. Supply the handle returned when the session was started.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 1024.  
Pattern: `urn:ietf:params:oauth:request_uri:[a-zA-Z0-9-._~]+`   
Required: No

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

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

{
   "accessToken": "string",
   "expiresAt": number,
   "sessionStatus": "string"
}
```

## Response Elements
<a name="API_GetOAuthToken_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_GetOAuthToken_ResponseSyntax) **   <a name="credentialbroker-GetOAuthToken-response-accessToken"></a>
The access token. Present it to the third-party API as a bearer credential.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 131072.

 ** [expiresAt](#API_GetOAuthToken_ResponseSyntax) **   <a name="credentialbroker-GetOAuthToken-response-expiresAt"></a>
When the access token expires. Absent when the authorization server does not report an expiry, in which case the token's lifetime is whatever that server applies.  
Type: Timestamp

 ** [sessionStatus](#API_GetOAuthToken_ResponseSyntax) **   <a name="credentialbroker-GetOAuthToken-response-sessionStatus"></a>
Status of the consent session named in the request, so a repeated call can tell whether the user has finished granting consent.  
Type: String  
Valid Values: `IN_PROGRESS | COMPLETED | FAILED` 

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

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

 ** AccessDeniedException **   
The caller is not authorized to perform the request, or a resource the request depends on refused access. `reason` distinguishes a denial by this service from a denial reported by a dependency the caller configured, such as a customer-owned secret, KMS key, or external identity provider, which usually points at a permission or configuration fix outside this API.  
HTTP Status Code: 403

 ** InternalServerException **   
The request failed because of an unexpected error in the service. Whether the request took effect is undefined, so for a create or update, read the resource back before retrying. Retryable: the same request may succeed later.    
 ** retryAfterSeconds **   
The number of seconds to wait before retrying. If this field is absent, retry with exponential backoff.
HTTP Status Code: 500

 ** ResourceNotFoundException **   
The requested resource does not exist, or the caller is not permitted to know that it exists. A resource that was deleted, or that is still being created, can also be reported this way.    
 ** resourceId **   
The identifier of the resource that could not be found, echoed from the request.  
 ** resourceType **   
The type of the resource named by `resourceId`, when present.
HTTP Status Code: 404

 ** ServiceQuotaExceededException **   
The request would exceed a service quota, so it was rejected and nothing was created or changed. Delete resources that are no longer needed, or request a quota increase in Service Quotas using `serviceCode` and `quotaCode`, then retry.    
 ** quotaCode **   
The Service Quotas requirement that identifies the originating quota.  
 ** resourceId **   
The identifier of the resource whose quota was exceeded, when the quota applies to a specific resource rather than the account.  
 ** resourceType **   
The type of the resource named by `resourceId`, when present.  
 ** serviceCode **   
The Service Quotas requirement that identifies the originating service.
HTTP Status Code: 402

 ** ServiceUnavailableException **   
A downstream dependency the broker relies on is temporarily unavailable, notably the customer's external IdP token/discovery endpoint (upstream 5xx, `server_error`, or `temporarily_unavailable`). Retryable: the same request may succeed later.    
 ** retryAfterSeconds **   
The number of seconds to wait before retrying. If this field is absent, retry with exponential backoff.
HTTP Status Code: 503

 ** ThrottlingException **   
The request was denied because the caller exceeded a request rate limit. Nothing was changed. Retry with exponential backoff, honoring `retryAfterSeconds` when it is present.    
 ** retryAfterSeconds **   
The number of seconds to wait before retrying. If this field is absent, retry with exponential backoff.
HTTP Status Code: 429

 ** ValidationException **   
The request is not valid. The request was rejected before any change was made, so it is safe to correct the input and retry. Use `reason` to branch in code and `message` for the human-readable detail of which field or combination of fields was at fault.  
HTTP Status Code: 400

## See Also
<a name="API_GetOAuthToken_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/credentialbroker-2026-07-01/GetOAuthToken) 
+  [AWS SDK for .NET V4](https://docs.aws.amazon.com/goto/DotNetSDKV4/credentialbroker-2026-07-01/GetOAuthToken) 
+  [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/credentialbroker-2026-07-01/GetOAuthToken) 
+  [AWS SDK for Go v2](https://docs.aws.amazon.com/goto/SdkForGoV2/credentialbroker-2026-07-01/GetOAuthToken) 
+  [AWS SDK for Java V2](https://docs.aws.amazon.com/goto/SdkForJavaV2/credentialbroker-2026-07-01/GetOAuthToken) 
+  [AWS SDK for JavaScript V3](https://docs.aws.amazon.com/goto/SdkForJavaScriptV3/credentialbroker-2026-07-01/GetOAuthToken) 
+  [AWS SDK for Kotlin](https://docs.aws.amazon.com/goto/SdkForKotlin/credentialbroker-2026-07-01/GetOAuthToken) 
+  [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/credentialbroker-2026-07-01/GetOAuthToken) 
+  [AWS SDK for Python (Boto3)](https://docs.aws.amazon.com/goto/boto3/credentialbroker-2026-07-01/GetOAuthToken) 
+  [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/credentialbroker-2026-07-01/GetOAuthToken) 