What roles do consumer keys and consumer secrets play during OAuth authentication handshakes?
Answer
Basics: OAuth separates the user's identity from the client application's identity. When the Connected App is created, Salesforce generates the Consumer Key (client_id) and Consumer Secret (client_secret). The key says which app is asking; the secret proves it really is that app. The user's own password is never given to the app in the code-based flows.
How it works:
- The app sends the user to the authorization endpoint with
client_id(the key). - The user authenticates and approves; Salesforce returns an authorization code.
- The app's server posts the code to
/services/oauth2/tokenwithclient_idandclient_secret(and the PKCEcode_verifier). - Salesforce validates the pair and returns an access token and refresh token.
- Later refresh requests also present the key (and the secret if required by policy).
- Flows differ: Web Server and Client Credentials use the secret; JWT Bearer uses the key plus a signed assertion from a certificate (no secret); User-Agent flow uses only the key.
Advanced / deep dive: The key is not a secret in the cryptographic sense (it appears in browser URLs), so the secret and any certificates are what need protection. For public clients, PKCE replaces the secret by binding the code to a one-time verifier. Salesforce lets you require the secret for the Web Server flow and refresh token flow, or relax it for PKCE-only public apps. Treat the secret like a password: store in a vault or Named/External Credential, never in client-side code or Git, and rotate it (you can reset it; resetting breaks existing deployments). Combine with IP restrictions and admin pre-authorization. For server-to-server with no user, prefer JWT Bearer with certificates because there is no shared secret to leak.