View a markdown version of this page

CreateOAuth2TokenWithTokenExchange - AWS Sign-In

CreateOAuth2TokenWithTokenExchange

Exchanges a supported token for an OAuth 2.0 access token scoped to a resource, which you can use to access AWS services from applications.

The issued access token is valid for up to 1 hour (3600 seconds).

Request Syntax

POST /v1/token?x-amz-oauth-token-method=token-exchange HTTP/1.1 Content-type: application/json { "assertion": "string", "client_id": "string", "grant_type": "string", "resource": "string", "scope": "string", "subject_token": "string", "subject_token_type": "string" }

URI Request Parameters

The request does not use any URI parameters.

Request Body

The request accepts the following data in JSON format.

assertion

The JWT authorization grant, as defined in RFC 7523. Required when grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer.

Type: String

Length Constraints: Minimum length of 4. Maximum length of 20000.

Required: No

client_id

The OAuth 2.0 client identifier. If provided with grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer, must match the assertion's client_id claim.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 212.

Required: No

grant_type

The OAuth 2.0 grant type. Currently supports urn:ietf:params:oauth:grant-type:token-exchange and urn:ietf:params:oauth:grant-type:jwt-bearer.

Type: String

Pattern: urn:ietf:params:oauth:grant-type:(token-exchange|jwt-bearer)

Required: Yes

resource

The OAuth resource for which the access token is requested:

  • grant_type=urn:ietf:params:oauth:grant-type:token-exchange: Required. Must be a service principal. Example: glue.amazonaws.com.

  • grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer: Required when the assertion has no resource claim, otherwise must match it. Must be a URI. Example: https://aws-mcp.us-east-1.api.aws/mcp.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 2048.

Required: No

scope

The IAM managed policy Amazon Resource Names (ARNs) to apply as session policies that further scope down the permissions of the issued access token, provided as a space-delimited list. Example: arn:aws:iam::444455556666:policy/MyPolicy.

If provided with grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer, must match the assertion's scope claim.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 4096.

Required: No

subject_token

The subject token that represents the identity of the party on whose behalf the request is made. Required when grant_type=urn:ietf:params:oauth:grant-type:token-exchange.

Type: String

Length Constraints: Minimum length of 4. Maximum length of 20000.

Required: No

subject_token_type

The token type of the subject token. Currently only supports urn:ietf:params:oauth:token-type:jwt. Required when grant_type=urn:ietf:params:oauth:grant-type:token-exchange.

Type: String

Pattern: urn:ietf:params:oauth:token-type:.+

Required: No

Response Syntax

HTTP/1.1 200 Content-type: application/json { "access_token": "string", "expires_in": number, "issued_token_type": "string", "resource": "string", "scope": "string", "token_type": "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.

access_token

The access token containing principal identity, resource scope, and session metadata. Use this token as a Bearer token when accessing the target resource.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 4096.

expires_in

The token lifetime in seconds. Value is the minimum of the provided token's validity and 1 hour (3600 seconds).

Type: Integer

Valid Range: Minimum value of 1. Maximum value of 3600.

issued_token_type

The token type of the issued token. Returned when grant_type=urn:ietf:params:oauth:grant-type:token-exchange. Value is urn:ietf:params:oauth:token-type:access_token as defined in RFC 8693 ยง2.2.1.

Type: String

Pattern: urn:ietf:params:oauth:token-type:access_token

resource

The resource the access token is scoped to. Returned when grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 2048.

scope

The IAM managed policy ARNs applied as session policies, as a space-delimited list. Returned when grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer and the assertion has a scope.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 4096.

token_type

The token type. Currently only supports Bearer as defined in RFC 6749.

Type: String

Pattern: Bearer

Errors

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

InternalServerException

The request failed because of an internal server error.

HTTP Status Code: 500

InvalidGrantException

The request failed because the provided grant is invalid or expired.

HTTP Status Code: 400

InvalidScopeException

The request failed because the requested scope is invalid or exceeds the scope that can be granted.

HTTP Status Code: 400

ServiceUnavailableException

The request failed because a dependency is temporarily unavailable. You can retry the request.

HTTP Status Code: 503

TooManyRequestsError

The request failed because you exceeded the request rate limit for this operation.

HTTP Status Code: 429

ValidationException

The request failed because it contains a malformed, missing, or invalid parameter.

HTTP Status Code: 400

See Also

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