View a markdown version of this page

Obtain a token with the token exchange grant - AWS Identity and Access Management

Obtain a token with the token exchange grant

Note

This is prerelease documentation for a service in preview release. It is subject to change.

The token exchange grant obtains a token for a downstream service that represents an end user who is already signed in. Credential Broker presents a token that identifies the user, called the subject token, to the authorization server and receives a new token for the downstream service. Your application makes one call and writes no token exchange logic. The grant follows the token exchange standard, RFC 8693. For Microsoft Entra ID, Credential Broker uses the JWT bearer grant (JWT_AUTHORIZATION_GRANT, RFC 7523) instead.

Key characteristics

  • The token represents the end user, not the application.

  • There is no new consent prompt once a subject token exists.

  • Credential Broker locates the subject token and performs the exchange. Your application never handles the subject token.

  • Supported vendors for token exchange are Microsoft, Okta, Salesforce, and custom OAuth 2.0 authorization servers.

Example scenario

Employees use a customer-built internal application that runs on Amazon ECS to query their own data through the company's internal HR API, which is protected by the company's own identity provider.

  1. Omar (identity admin) creates a credential provider pool and a credential provider that allows the token exchange grant and connects to the company's identity provider, and grants the application's role permission to call the broker.

  2. Grace (application developer) calls the broker with the provider ARN and the scopes the HR API needs.

  3. Sam (end user) asks for his data and isn't prompted again. The HR API applies its own per-user access control and returns only Sam's data.

Subject token sources

Each token exchange provider names where its subject token comes from, with the subjectTokenSource setting. Set exactly one source.

iamIdentityCenter

The subject token comes from the user's IAM Identity Center session. The exchange is silent from the first call. The credential provider pool must be associated with an IAM Identity Center instance.

credentialProvider

The subject token comes from a separate provider that allows the authorization code grant. The user consents once with that provider, and later exchanges are silent.

credentialProviderSelf

The same provider allows both the authorization code grant and the token exchange grant, and the subject token comes from the user's consent with that provider.

Two optional settings control the exchange request. The requester configuration (tokenExchangeRequesterConfiguration) sets how the provider authenticates to the authorization server for the exchange, which can be a different client from the one that obtained the subject token. The actor configuration (tokenExchangeActorConfiguration) adds an actor token that identifies the party acting on the user's behalf. Omit it to send no actor token.

Carry the end user's identity in the IAM session

Credential Broker identifies the end user from the AWS credentials that sign each call. Your application must call the broker with a per-user session that carries the end user's identity, not with the application's own role session. Credential Broker uses that identity to key the user's tokens and to check that the same user completes a consent session that they started. Use one of the following options.

Option A: IAM federation

The user signs in to your application through an external OpenID Connect (OIDC) or SAML identity provider. Your application exchanges the user's ID token or SAML assertion for a role session with AssumeRoleWithWebIdentity or AssumeRoleWithSAML. The session carries the issuer and subject of the user.

Option B: IAM Identity Center

The user signs in to your application through IAM Identity Center. Your application calls CreateTokenWithIAM to obtain the user's IAM Identity Center token, then calls AssumeRole with the identity context from that token to create an identity-enhanced session. This option uses trusted identity propagation. For token exchange from an IAM Identity Center source, the credential provider pool must be associated with an IAM Identity Center instance.

Create the per-user session for each user and call Credential Broker with it. Don't share one session across users, and don't cache tokens across users in your application.

How it works

To obtain a token with the token exchange grant
  1. Call GetOAuthToken on the token exchange provider with the grant type TOKEN_EXCHANGE and the scopes that the downstream service needs, signed with the user's per-user session. When the subject token comes from a consent, also pass the sessionUri from that consent.

  2. Credential Broker locates the subject token from the provider's subject token source. If no subject token exists for this user, the call fails with AccessDeniedException and the reason SUBJECT_TOKEN_MISSING. Run the authorization code consent flow once with the source provider, as described in Obtain a token on behalf of a user with the authorization code grant, and then call GetOAuthToken again.

  3. Credential Broker exchanges the subject token at the authorization server and returns the downstream access token and its expiration time. Later calls for the same user return the cached token until it expires.

  4. Call the downstream service with the access token in the Authorization: Bearer header.

A headless caller that can't show a browser can't complete the consent flow. Such a caller stops at the SUBJECT_TOKEN_MISSING reason by design. Use an IAM Identity Center source for callers that never interact with a user.

Security controls in this flow

Security controls for the token exchange grant
ControlWhat it protects against
Per-user IAM sessionCredential Broker finds the subject token for the user who signs the call, so a workload can't act as another user.
Subject token held by the brokerYour application never receives or forwards the user's subject token or refresh token.
Scoped downstream tokenThe exchanged token carries only the scopes that you request for the downstream service.
Separate requester and actorThe exchange can authenticate with its own client and name the acting party, so the authorization server sees who is acting for the user.
Session binding at seedingWhen the subject token comes from a consent, session binding protects that consent as described for the authorization code grant.
EncryptionStored tokens and secrets are encrypted with an AWS owned key by default, or with a customer managed AWS KMS key. For more information, see Security in Credential Broker.

Set up

  1. Create a credential provider pool. For an IAM Identity Center source, associate the pool with an IAM Identity Center instance.

  2. Create a credential provider that allows the token exchange grant, with the subject token source and, optionally, the requester and actor configuration. For a consent source, also create or reuse a provider that allows the authorization code grant. You reference the provider by its ARN, in the form arn:aws:credentialbroker:<region>:<account>:credentialproviderpool/<pool-id>/credentialprovider/<provider-id>.

  3. For an IAM Identity Center source, put an application access scope of credentialbroker:getoauthtoken on your application's IAM Identity Center application, with the pool's IAM Identity Center application as an authorized target, by using PutApplicationAccessScope.

  4. Set up the per-user session described in Carry the end user's identity in the IAM session.

  5. Grant the per-user role the credentialbroker: permissions for this flow. For more information, see Control access to AWS IAM Credential Broker.