OAuth Redirect And Domain Strategy
The Moving Parts
- My Domain — every org has one. Login host is now
acme.my.salesforce.com(prod) oracme--sandbox.sandbox.my.salesforce.com(sandbox). Classiclogin.salesforce.comandtest.salesforce.comstill work for initial auth but redirect to My Domain. - Enhanced Domains — enforced on all orgs. URL format stabilises across orgs; old URL patterns may break.
- Connected App Callback URLs — whitelist of exact match redirect
URIs. Mismatch at runtime =
redirect_uri_mismatcherror. - Login host — what the client sends token requests to.
login.salesforce.comworks for prod; for sandboxes prefer the sandbox My Domain directly.
Callback URL Design
- Exact match, not prefix.
https://app.example.com/callbackdoes NOT matchhttps://app.example.com/callback?x=1automatically. - Put the callback URLs for every environment the Connected App serves into the Connected App definition — prod callback AND uat AND dev. Missing one at cutover = downtime.
- Do not use wildcards — they are not supported.
Per-Environment Pattern
| Environment | Login Host | Client Callback |
|---|---|---|
| Production | login.salesforce.com | https://app.example.com/callback |
| UAT | test.salesforce.com | https://uat.example.com/callback |
| Developer sandbox | test.salesforce.com | https://dev.example.com/callback |
Clients usually have a per-env config toggle for base URL + login host.
My Domain Naming
- Short, lowercased, no dashes where avoidable.
- Keep it the same across refreshes — rename = client updates.
- For sandboxes: Salesforce appends
--<sandboxname>. Clients should read the host from an env var, not hardcode.
Enhanced Domains Cutover
- Old URL patterns (
c.na123.visual.force.com, etc.) change. - Inventory hardcoded URLs in:
- Apex (string literals, metadata mention).
- LWC/Aura (fetch targets).
- External systems (webhook registrations, integrations).
- Email templates (absolute links).
- Run the pre-cutover "known issues" scanner Salesforce provides.
- Rehearse in a sandbox first.
Login Host Strategy
- Prod clients: either
login.salesforce.comor the org's My Domain directly. My Domain is preferred (no redirect bounce). - Sandbox clients: the sandbox My Domain directly.
test.salesforce.comredirects and some OAuth libraries handle that redirect awkwardly.
Recommended Workflow
- Enumerate Connected Apps + environments.
- Build the redirect URI matrix (exact URLs per env).
- Audit hardcoded URLs across Apex, LWC, metadata, email templates, and external registrations.
- Standardise My Domain name; avoid renames.
- Point OAuth clients at the org's My Domain as the login host.
- Rehearse Enhanced Domains cutover in a sandbox.
- Monitor
redirect_uri_mismatchrates post-change.
Official Sources Used
- Connected App OAuth Configuration — https://help.salesforce.com/s/articleView?id=sf.connected_app_create_api_integration.htm
- My Domain Overview — https://help.salesforce.com/s/articleView?id=sf.domain_name_overview.htm
- Enhanced Domains — https://help.salesforce.com/s/articleView?id=sf.domain_name_enhanced_domains_overview.htm