OpenID Connect, Auth. Providers and social sign-on
OIDC as identity on top of OAuth: Salesforce as a relying party through Auth. Providers and registration handlers, Salesforce as an OIDC provider, and social sign-on for customers.
Simple explanation
OpenID Connect (OIDC) adds identity to OAuth 2.0. Besides an access token, the identity provider returns an ID token (a signed JWT with claims such as sub, email, name) and offers a UserInfo endpoint.
Salesforce as relying party (logging in with another provider)
- Configure an Auth. Provider (types for OpenID Connect, Microsoft, Google, Apple, Facebook, LinkedIn, Salesforce and others).
- A registration handler Apex class (
Auth.RegistrationHandler) decides how to match or create the Salesforce user from the provider's data (createUser,updateUser). - Add the provider to My Domain or Experience Cloud login pages. This is how social sign-on works for customer sites.
Salesforce as OIDC provider (other apps log in with Salesforce)
- Register the app (an External Client App) with the
openidscope; the app receives an ID token and can call UserInfo. - Useful when Salesforce (often an Experience Cloud site) is the customer identity for other web or mobile apps.
SAML or OIDC? SAML is common for workforce SSO with enterprise IdPs; OIDC is natural for modern web and mobile apps, social login and customer identity, and is JSON/JWT-based.
Real-world analogy
OAuth gives an app a key to certain rooms. OIDC also gives it a name badge: a signed card that says who the person is (the ID token), so the app can greet them by name and link them to their account.
Worked example
Customer portal with "Sign in with Google" and "Sign in with Apple":
global class CustomerRegistrationHandler implements Auth.RegistrationHandler {
global User createUser(Id portalId, Auth.UserData data) {
// Match an existing customer by verified email, otherwise create a new person account and user.
List<User> existing = [SELECT Id FROM User WHERE Email = :data.email AND IsActive = true AND ContactId != null LIMIT 1];
if (!existing.isEmpty()) {
return existing[0];
}
Account person = CustomerOnboarding.createPersonAccount(data.firstName, data.lastName, data.email);
return CustomerOnboarding.newCommunityUser(person, data.email, data.firstName, data.lastName);
}
global void updateUser(Id userId, Id portalId, Auth.UserData data) {
// Keep profile details in sync without overwriting values the customer manages in the portal.
}
}
Only trust verified email claims from the provider, and link accounts deliberately, so someone can't take over an account by registering an unverified address elsewhere.
Diagram
Key points
- OIDC = OAuth + identity (ID token, UserInfo).
- Auth. Providers let users log in with external providers; registration handlers match or create users.
- Social sign-on for Experience Cloud customers.
- Salesforce can be an OIDC provider for other apps (
openidscope). - SAML for many workforce IdPs; OIDC for modern apps and customer identity.
- Trust only verified claims when linking accounts.
Limits and gotchas
- Account linking by email is risky if the provider's email isn't verified.
- Registration handlers run during login; slow logic or failures block sign-in. Keep them lean and handle errors clearly.
- Each provider has its own token and claim formats; test with real provider accounts in sandboxes.
- Customer identity (Experience Cloud) licensing and login-based pricing affect the design β verify.
π€ How to say this in an interview
Expect "how would customers log in with Google to our portal?" Describe the Auth. Provider, the registration handler logic (match vs create, verified email), and what happens on second login (updateUser). Then contrast with SAML for employees.
Common follow-ups
How do you stop duplicate customer users when they sign in with Google and Apple?
Match on a verified email (or a customer number collected at registration) in the registration handler and link both providers to the same user, instead of creating a new user per provider.
When would you choose OIDC over SAML for employees?
When the IdP and apps are OIDC-native, or when the same identity serves web and mobile apps. Many enterprises use SAML for Salesforce simply because their IdP setup is standardised on it; both are valid.