Token Exchange with External Identity Providers
Choreo Identity & Access Management can exchange a token issued by an external identity provider (IdP) for a Choreo Identity & Access Management-issued access token. This lets a client that authenticates users via an external OIDC provider, such as Asgardeo, Google, Azure AD, or Keycloak, obtain a Choreo Identity & Access Management-scoped access token without requiring users to sign in again.
This uses RFC 8693 Token Exchange. For general information about the token exchange grant type, see Token Exchange.
When to Use
Use this when:
- A client authenticates users via an external OIDC provider and needs a Choreo Identity & Access Management-scoped access token to call Choreo Identity & Access Management-protected APIs.
- You want to centralize token issuance through Choreo Identity & Access Management while delegating user authentication to an upstream IdP.
Token exchange accepts an external token and issues a new Choreo Identity & Access Management token in return.
Prerequisites
- Choreo Identity & Access Management is running. See Get Started.
- An external OIDC identity provider that issues JWTs with an
issclaim and exposes a JWKS endpoint. - You can sign in to the Choreo Identity & Access Management Console.
Step 1: Register the External Identity Provider
Register the external IdP in Choreo Identity & Access Management as an OpenID Connect connection and enable it for token exchange. An OIDC connection is a single typed resource, so the sign-in fields (Client ID, Client secret, Authorization endpoint, and Token endpoint) are required even when the IdP is used for token exchange only.
-
Create the connection as described in Add an OIDC Identity Provider.
-
Open the connection and, on its edit page, set these fields:
Field Description Issuer The exact issclaim value in tokens from this IdP. Choreo Identity & Access Management matches incoming tokens against this value to identify which IdP issued them.JWKS endpoint The IdP's JWKS URL. Choreo Identity & Access Management fetches public signing keys from this URL to verify token signatures. -
Under Federation, turn on Enable token exchange to allow this IdP's tokens to be exchanged. Issuer and JWKS endpoint become required.
-
Click Save changes.
The Console creates the connection in your own organization unit, and the connection stays there. See Organization Unit Ownership.
Step 2: Allow the Token Exchange Grant on an Application
Choose the application that will perform exchanges on behalf of users, and allow the token exchange grant on it.
- In the Choreo Identity & Access Management Console, open Applications and select the application.
- Open the Advanced tab.
- Under Grant types, add Token exchange.
- Save.
Note the application's client ID and client secret for the next step.
Step 3: Exchange the External Token
Send the external IdP token to Choreo Identity & Access Management's token endpoint using the token exchange grant type:
curl -X POST https://thunderid.example.com/oauth2/token \
-u '<client-id>:<client-secret>' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
-d 'subject_token=<JWT_FROM_EXTERNAL_IDP>' \
-d 'subject_token_type=urn:ietf:params:oauth:token-type:jwt' \
-d 'resource=https://api.example.com/app'
A successful response returns a Choreo Identity & Access Management-issued access token:
{
"access_token": "eyJ...",
"token_type": "Bearer",
"expires_in": 3600,
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token"
}
The issued token's sub claim contains the external user's subject identifier from the original token. For permission-bearing requests, its aud claim is the explicit resource server identifier or the configured defaultResourceServer. An OIDC-only or scopeless request without resource uses the application's default audience (token.accessToken.defaultAudience), or the client_id when it is unset.
How Choreo Identity & Access Management Validates the External Token
When processing an external token for exchange, Choreo Identity & Access Management:
- Extracts the
issclaim and matches it against registered IdPs that have Enable token exchange turned on. - Fetches the matching IdP's JWKS and verifies the token signature.
- Checks the token's
audclaim. Choreo Identity & Access Management accepts the token whenaudcontains this Choreo Identity & Access Management instance's own issuer. - Validates
exp(andnbfif present) with the configured clock-skew leeway. - Extracts the
subclaim and non-standard claims as user attributes.
If any step fails, the exchange returns HTTP 400 with error=invalid_request and an "Invalid subject_token" message.
Attribute Configuration
Attribute configuration for token exchange uses the connection's Attribute configuration tab, the same as federated sign-in, including Authorization Mapping. See Add an OIDC Identity Provider for the full reference.
When the IdP connection has Authorization Mapping configured, it decides the granted scope instead of the external token's own scope claim:
| Request | Resulting scope |
|---|---|
scope supplied | The requested scopes, narrowed to whatever the mapping actually authorizes |
scope omitted | Nothing. An omitted request is not treated as "grant everything the mapping allows" here — unlike the jwt-bearer grant, which does bound an omitted request by the assertion's own scope claim, token exchange has no equivalent claim on the subject token to fall back to, since an arbitrary external token's own scope claim is never authoritative here either way. |
Without Authorization Mapping configured, the granted scope narrows the requested scope against the external token's own scope claim, same as any other token exchange.
Limitations
- Only JWT tokens are supported. Opaque tokens (for example, GitHub access tokens) cannot be exchanged.
- The external user's
subis passed through as-is. No local user lookup or just-in-time provisioning occurs. - External token scopes are narrowed by the existing intersection logic, or by the connection's Authorization Mapping when one is configured (see Attribute Configuration above). External claims can be renamed to local attributes on the connection's Attribute configuration tab; the resulting attributes are still filtered by the user attributes the application's tokens carry.
- Token exchange is available to all applications that have the token exchange grant type. No per-application IdP restriction applies.
Next Steps
- Manage Identity Providers: Create, update, and delete identity providers in the Console.
- Connect an IdP to an Application: Use an IdP for redirect-based sign-in flows.
- Token Exchange: Learn about the RFC 8693 token exchange grant type in Choreo Identity & Access Management.
Was this page helpful?