Token Exchange
Module 4 of 5 in the chapter Acting as Someone: The Impersonation Flows, chapter 11 of Securing Salesforce: Identity and Access. Each module stands on its own.
The question this module answers: What if Priya is already signed in, just not at Salesforce, and an app needs her Salesforce data?
Signed in, somewhere else
Section titled “Signed in, somewhere else”Modules 1 to 3 had nobody home. This one is different: Priya is right there. She’s signed in. Just not at Salesforce.
Say the Burger House has its own login, run by its own identity provider, the one it uses for everything: its menu, its payments, its loyalty points. Whichever pops up the login screen is the identity provider, and here it isn’t Salesforce. Priya signed in there, and the Burger House holds her token from it.
Now she asks for her drink, and her drink is at the festival, in Salesforce. Does the Burger House send her to Salesforce’s login page, like chapter 9? She’s already signed in once. Asking again would be annoying, and she may not even know she has a Salesforce user.
Salesforce’s own example is the same story with real things: a customer portal outside Salesforce, using a third-party identity provider, with payments, shipping and customer data in other services, and support cases in Salesforce. The customers log in to the portal and see their cases, “without ever directly logging in to Salesforce” (S5).
The swap
Section titled “The swap”You’ve seen this move before. In single sign-on, the identity provider’s assertion wasn’t good enough to get data on its own: Salesforce exchanged it for a session. In the web server flow, the code was exchanged for a wristband. Token exchange is the same idea, said out loud: the Burger House takes the token it already has, from the other identity provider, and swaps it for a Salesforce one.
- Priya is already signed in at the Burger House’s identity provider, and the Burger House holds her token.
- She asks for her drink. No Salesforce login page.
- The Burger House posts her token to Salesforce’s token endpoint, saying what kind of token it is and which handler should check it (S5, S6).
- Salesforce runs your token exchange handler. It checks the token, and can ask the identity provider whether the token is good and who she is. Then it maps her to a Salesforce user (S5).
- Salesforce returns its tokens: an access token, and, if asked for, “a refresh token or ID token” (S5).
- The Burger House fetches her drink as Priya.
The handler: chapter 10 again
Section titled “The handler: chapter 10 again”Does step 4 sound familiar? It should. In chapter 10, the registration handler took what Google said about Priya and decided which Salesforce user she was. The token exchange handler does the same job, for a token instead of a login. It’s an Apex class you write. It validates the outside token, maps the person in it to a Salesforce user, and “If it can’t find an existing user, it sets up a new User object and returns it to Salesforce for automated insertion” (S5).
So everything from chapter 10, module 3, applies here too:
- Validate the token properly, with the identity provider’s keys, or by asking it. The handler is where the trust decision is made.
- Match carefully, on something you can trust, and refuse rather than guess.
- Only create users you mean to, with the right profile and licence.
On the wire
Section titled “On the wire”The request is one POST to /services/oauth2/token, on your My Domain login URL or Experience Cloud site URL (S6):
| Parameter | What it holds |
|---|---|
grant_type | urn:ietf:params:oauth:grant-type:token-exchange; for hybrid mobile apps, urn:ietf:params:oauth:grant-type:hybrid-token-exchange |
subject_token | The token from the other identity provider |
subject_token_type | What kind it is: an access token, a refresh token, an ID token, a SAML assertion, or any JWT |
client_id | The app’s consumer key |
token_handler | Which handler checks it; optional, but “strongly recommended” |
scope | Optional; a subset of the app’s scopes |
Notice what it accepts: almost any token the other side might have, from an opaque access token to a SAML assertion (S6). And the client secret? Only if the app has a private back end that can keep it. For mobile apps and single-page apps, Salesforce says “we don’t recommend sending a secret because it can get leaked through the browser” (S6). Chapter 9’s rule, again.
Where it fits
Section titled “Where it fits”On the map (chapter 5, module 3), token exchange sits in the row “A person, through an app”, beside the web server flow. That’s because there’s a person: Priya signed in, just somewhere else. That’s also why it can return a refresh token and an ID token, where modules 1 to 3 never could.
It’s the right tool when a company already has a central identity provider in front of many apps and services, and Salesforce is one more service behind it (S5). Salesforce fits into the identity design you already have, instead of the other way round.
It’s available in Enterprise, Performance, Unlimited and Developer editions (S5).
How is it different from chapter 10’s auth provider? The auth provider brings Priya into Salesforce itself, through its login page: she clicks a button and lands in Salesforce. Token exchange gives an app a Salesforce token for her, and she never sees Salesforce at all.
What’s next
Section titled “What’s next”Module 5: the asset token. Things, not people.
What an architect decides here
Section titled “What an architect decides here”- Whether Salesforce should fit behind an existing identity provider, or be signed in to directly.
- What the handler trusts: how it validates the token, and how it maps the person.
- Whether the handler may create users, and which ones.
- Whether the app sends a secret: only with a private back end.
Explore
Section titled “Explore”- Token Exchange Flow Diagram and Process (opens in a new tab) (Salesforce Help, Winter ‘27; checked 2026-11-07)
- Set Up the Token Exchange Flow (opens in a new tab) (Salesforce Help, Winter ‘27; checked 2026-11-07)
