# How do External Credentials decouple authentication providers from endpoint configurations in modern Salesforce architecture?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, External Credentials, Authentication Architecture

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-external-credentials-decouple-authentication-providers-from-endpoint-configurations-in-modern

## Answer

**Basics:** Before Winter '23, a Named Credential combined URL and auth in one record, so ten endpoints on the same OAuth provider needed ten copies. The new model separates **what to call** (Named Credential: URL, headers) from **how to authenticate** (External Credential: protocol and principals), and separates **who can use it** (permission sets).

**How it works:**
1. Create an Auth Provider or choose another protocol for the External Credential: OAuth 2.0 (browser flow or JWT bearer, client credentials), Basic, AWS Signature v4, Custom, and others.
2. Add a **Principal**: Named Principal (shared identity, secrets stored in Salesforce) or Per User Principal (each user authorizes).
3. Create one or more Named Credentials pointing to the External Credential and give each its base URL.
4. Open a permission set and add **External Credential Principal Access** for the principal.
5. Assign the permission set to the users or integration user whose Apex or Flow makes the call.
6. At callout time Salesforce checks the user's principal access, builds the auth header and sends the request.

**Advanced / deep dive:** The principal-access check is an extra security layer: even an admin cannot call the endpoint through Apex unless granted. Custom headers can reference the credential parameters (formulas like `{!$Credential.<ExternalCredentialName>.<ParameterName>}`), which suits APIs needing API keys plus a bearer token. Rotating a secret changes one external credential, not every endpoint. Authentication problems are isolated from URL problems, and sandbox refreshes need only the secret re-entered. Per-user principals preserve end-user identity downstream (audit, row-level security in the target) but need an onboarding step where each user authenticates; use named principals for system-to-system integration. Metadata for External Credentials deploys, but secrets do not.

**Code / config example:** Setup path:
```
Setup > Named Credentials > External Credentials > New (Protocol: OAuth 2.0, Flow: Client Credentials)
  > Principals > New (Named Principal, Identity Type: Named Principal)
Setup > Named Credentials > New (URL: https://api.example.com, External Credential: ERP_Auth)
Setup > Permission Sets > Integration_PS > External Credential Principal Access > add ERP_Auth - Named
```
Apex remains `req.setEndpoint('callout:ERP_NC/path');`.

**Hidden gotchas & must-remember points:**
- Missing permission set principal access is the number one cause of "unauthorized" callouts after migration.
- Salesforce provides a migration tool to convert legacy Named Credentials; verify steps in current docs.
- Secrets never travel with deployments.
- Per-user flows require each user to authenticate in Settings > Authentication Settings for External Systems.
- One external credential can serve many named credentials, but principals still need to be mapped.
- Tests still need `HttpCalloutMock`.

**Best practice:** Create one external credential per target system and auth type, keep endpoints as separate named credentials, and manage access only through permission sets.

---
Source: ForceChallenges · last updated 2026-11-02
