Use customTokenExchange() when one principal (the actor) needs to act on behalf of another (the subject), such as an AI agent acting for a user.
Crucial Difference: Unlike loginWithCustomTokenExchange(), this method has no side effects on the SDK's internal state. It does not update the current session, and isAuthenticated() or getUser() will remain unchanged. It simply returns a tokenResponse containing an access_token for use in downstream API calls.
const tokenResponse = await auth0.customTokenExchange({
subject_token: '<USER_TOKEN>',
subject_token_type: 'urn:acme:user-token',
actor_token: '<AGENT_TOKEN>',
actor_token_type: 'https://idp.example.com/token-type/agent',
audience: 'https://api.example.com'
});
// Use tokenResponse.access_token to call a downstream API
// The current user session is unchanged