Using Custom Token Exchange alongside Token Vault provides an interim solution for enabling AI agents without migrating user stores. Auth0 will soon support a native solution powered by ID-JAG (Cross App Access) to standardize cross-app authorization without requiring custom token exchange engineering.
Architecture overview
Prerequisites
- Auth0 tenant: An active tenant, with Organizations enabled if you are using multi-tenant or B2B structures.
- User IdP capabilities: A primary identity provider capable of issuing signed OIDC ID tokens or JWT assertions, backed by a public JWKS endpoint or static key for signature verification.
- Third-party developer credentials: Active client credentials (Client ID and Client Secret) for each downstream provider your AI agents need to access, such as GitHub, Google Workspace, or Salesforce.
- Tenant administrator access: Permissions within your Auth0 tenant to create client applications, configure OAuth connections, and deploy Custom Token Exchange Actions.
Step 1: Setup and application registration
Register and configure your application
Navigate to Applications > Applications and create your application. Configure it as a first-party, confidential, OIDC-conformant application with Custom Token Exchange enabled:- Disable Allow Refresh Token Rotation for the application. Repeated token retrievals rely on reusing the same subject token, so rotation would break downstream access.
- Under Advanced Settings > Grant Types, make sure Refresh Token and Token Vault are selected.
- Under APIs > Auth0 My Account API, grant the application access to the My Account API (obtained through a multi-resource refresh token) with these scopes:
read:me:connected_accountscreate:me:connected_accountsdelete:me:connected_accounts
Register downstream OAuth connections
For each third-party provider your AI agents need to access:- Navigate to Authentication > Social or Authentication > Enterprise.
- Add the connection using credentials from the provider’s developer portal.
- Under Purpose, enable Connected Accounts for Token Vault on the connection.
- Under Permissions, select
Offline Access, allowing your client application to obtain a refresh token from the external provider. - Under the connection’s Applications tab, enable your registered application.
Step 2: Configure the Custom Token Exchange Action
Create a new Action under Actions > Library > Custom using the Custom Token Exchange trigger (onExecuteCustomTokenExchange). This Action validates the token issued by your User IdP, creates a shadow user profile in Auth0, and, optionally, scopes the access token to an Auth0 Organization.
subject_token_type to this Action. The URN must not use a reserved namespace (urn:ietf, urn:auth0, urn:okta, and so on):