Skip to main content
To configure the Custom Token Exchange for your application, you need to:

Prerequisites

Before configuring the Custom Token Exchange, make sure your application meets the following prerequisites:

Enable Custom Token Exchange for your application

Custom Token Exchange can be enabled across multiple applications. By default Custom Token Exchange is disabled for an application, to enable it:
  1. Navigate to Applications > Applications and select your application.
  2. Select the Settings tab.
  3. Find Custom Token Exchange and toggle it on.
  4. Select Save.
Once Custom Token Exchange is enabled for the application, also enable the connection you want to use with Custom Token Exchange for the application.
Custom DBs with import mode ON are only supported for setUserById() operations.
Note the application’s client_id and client_secret for later use when calling the /oauth/token endpoint.

Configure Custom Token Exchange Profile

Each Custom Token Exchange Profile establishes a one-to-one mapping between a subject_token_type and an Action, which contains the code logic for a specific use case. Custom Token Exchange requests sent to the /oauth/token endpoint with a specific subject_token_type value will map to the corresponding Custom Token Profile and route to the associated Action for processing. Use the Custom Token Exchange Event and API objects to write the Action associated with a profile. The Action should:
  • Decode and validate the subject_token based on the subject_token_type. This will provide you with information about the user for the transaction.
  • Enforce any authorization policy you may need to apply for the transaction.
Once you are sure the transaction can proceed, set the user. Auth0 will then issue access, ID, and refresh tokens for this user as a form of user authentication. To learn from example Custom Token Exchange Actions, read Example Use Cases and Code Samples.
subject_token_type must be a unique URI starting with https:// or urn. The following namespaces are reserved and you can’t use them: http://auth0.com, https://auth0.com, http://okta.com, https://okta.com, urn:ietf, urn:auth0, urn:okta.
  1. Navigate to Authentication > Custom Token Exchange and select Create Profile.
  2. In the Create Profile dialog:
    • Enter a Name for the profile.
    • Enter a unique Subject Token Type.
    • Choose how to provide the Action associated with this profile:
      • Start from scratch: enter a Name for the new Action. Auth0 creates an empty Action, bound to the Custom Token Exchange trigger, once you create the profile.
      • Create from Template: select an Action Template. Auth0 creates a new Action prefilled with the template’s code.
      • Use existing: select an existing Action already bound to the Custom Token Exchange trigger.
  3. Select Create. Auth0 creates the profile — and the Action, if you chose to create a new one or one from a template — and takes you to the profile’s Details page.
  4. On the Details page:
    • Edit the profile’s Name or Subject Token Type as needed.
    • Edit the associated Action’s Name as needed.
    • Use the inline code editor to edit the associated Action’s code. Select Save to save a draft, or Deploy to deploy a new version of the Action.
Once a profile is created, you cannot change which Action it’s associated with.

Manage Custom Token Exchange Profile

  1. Navigate to Authentication > Custom Token Exchange to see the list of your Custom Token Exchange Profiles, showing each profile’s Name, Subject Token Type, and Action ID.
  2. Select a profile to open its Details page, where you can edit its Name, Subject Token Type, and the associated Action’s Name and code (see Configure Custom Token Exchange Profile above).
  3. To delete a profile, select the options menu (the three-dot icon) next to it in the list, then select Delete.
An Action bound to a Custom Token Exchange Profile cannot be deleted on its own. Delete the profile first, then delete the Action if you no longer need it.