P

PKCE (Proof Key for Code Exchange)

An OAuth 2.0 extension (RFC 7636) that binds an authorization code to the client that requested it, so an intercepted code cannot be exchanged for tokens.

What it is

PKCE — Proof Key for Code Exchange, pronounced "pixy" — is an extension to the OAuth 2.0 authorization code flow, defined in RFC 7636. Before redirecting the user to sign in, the client generates a random secret called the code verifier and sends only a derived code challenge, normally the SHA-256 hash of the verifier (method S256). When it later exchanges the authorization code for tokens, it must present the original verifier. The authorization server hashes it and refuses the exchange unless it matches the challenge it received.

Why it matters

An authorization code travels through the browser, where it can be intercepted by a malicious app, a leaky redirect or a log. Without PKCE, whoever holds the code can redeem it. With PKCE the code is useless on its own, because only the client that started the flow knows the verifier. That is why it matters most for apps that cannot keep a client secret — single-page apps, mobile apps, CLIs and desktop tools — and why current guidance now recommends it for every client, confidential ones included.

Key components

  • Code verifier — a high-entropy random string (43–128 characters) kept by the client
  • Code challenge — BASE64URL(SHA-256(verifier)) sent with the authorization request
  • code_challenge_method — S256 (recommended) or plain
  • Verifier presented at the token exchange and checked by the authorization server

How it connects

PKCE hardens the OAuth 2.0 authorization code flow rather than replacing it. On Salesforce it applies to the web server (authorization code) flow, and a Connected App or External Client App can be set to require it. The Model Context Protocol authorization spec requires MCP clients to implement PKCE, so it is part of connecting an agent to a protected server.

Good to know

PKCE replaces the implicit flow for browser apps; it does not replace client authentication for a server that can hold a secret — a confidential client should use both. Always use S256: the plain method sends the verifier itself as the challenge and only exists for clients that cannot hash.

Need Help Implementing This?

We specialize in putting AI and Agentforce to work for Salesforce customers. Let's talk about your use case.

Book Intro Call