Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
PKCE stops a stolen OAuth authorisation code being redeemed by anyone else: the client proves it started the flow by revealing a secret it generated at the beginning.

What Is PKCE?
PKCE—pronounced “pixy”, and standing for Proof Key for Code Exchange—was written in 2015 to fix a specific hole in OAuth on mobile devices. It has since become the recommended practice for every client type, confidential ones included. RFC 7636 is the specification.
In the authorisation code flow, the authorisation server redirects the browser back to the application with a code in the URL, and the application then exchanges that code for tokens. A web application running on a server also sends its client secret during the exchange, which proves it is the application the code was issued to.
A mobile application cannot do that. Anything shipped inside an app binary can be extracted, so a mobile client has no secret. On older mobile platforms the redirect happened through a custom URI scheme—something like myapp://callback—and any other application on the device could register the same scheme. A malicious app that did so would receive the authorisation code and, with no client secret required, exchange it for tokens itself.
PKCE makes the client prove it is the one that started the flow, using a secret created per-request rather than embedded in the application.
code_challenge_method=S256 in the authorisation request.GET /authorize?response_type=code
&client_id=mobile-banking-uk
&redirect_uri=https%3A%2F%2Fapp.example.co.uk%2Fcb
&scope=openid accounts.read
&state=9f2c41ab7d
&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
&code_challenge_method=S256
An attacker who intercepts the code has only a hash. Reversing SHA-256 is not an option, so the code is useless to them. The secret that matters never travels in the first message, which is what makes the scheme work without any pre-registered credential.
The specification permits code_challenge_method=plain, where the challenge is the verifier itself. It exists only for devices that genuinely cannot compute SHA-256, which in practice means nothing you are likely to build. With plain, an attacker who can see the authorisation request sees the verifier and can redeem the code normally.
Servers should reject plain outright. Clients should always send S256. If a library offers a choice, that is a configuration decision worth checking rather than leaving at a default.
The original scope was public clients. The OAuth 2.0 Security Best Current Practice document, and OAuth 2.1 which consolidates current guidance, now recommend PKCE for all clients.
The reason is authorisation code injection. Consider an attacker who obtains a code issued for their own account—trivially, since they can start a flow themselves—and injects it into a victim’s session with the application. Without PKCE, the application exchanges it and binds the attacker’s account to the victim’s session, or in some designs the reverse: the victim’s data becomes accessible under the attacker’s account. The state parameter does not prevent this because it protects against cross-site request forgery rather than code substitution.
With PKCE the injected code fails at exchange, because the verifier in the client’s session does not correspond to the challenge the code was issued against. For OpenID Connect clients the nonce claim provides a similar binding for identity tokens, and using both is the correct answer rather than choosing between them.
state parameter. PKCE complements them; it replaces neither.Most modern libraries implement this correctly if you let them. The failures found in assessments are usually hand-rolled implementations, or a server that accepts a token exchange with no verifier at all when the challenge is absent—which lets an attacker simply omit PKCE from the authorisation request and bypass the whole mechanism. For the surrounding context, see OAuth 2.0, OpenID Connect, and DPoP for binding the tokens that follow.
At Privia Security, we test authorisation flows for code interception and injection in our mobile application security services.
For public clients it provides the protection a client secret cannot, since those clients have no way to keep a secret. For confidential clients it does not replace the secret; both are used together. The secret authenticates the application to the token endpoint, while PKCE binds the authorisation code to the particular request that produced it.
Yes, current guidance recommends it for every client type. A confidential client is still exposed to authorisation code injection, where an attacker feeds a code from their own flow into a victim’s session. PKCE prevents that because the verifier held in the legitimate client’s session will not match the challenge the injected code was issued against.
With S256 the challenge is the SHA-256 hash of the verifier, so an attacker who sees the authorisation request learns nothing useful. With plain the challenge is the verifier itself, so anyone observing the request can redeem an intercepted code. Plain exists only for devices that cannot hash; servers should reject it and clients should never send it.
No. It protects the authorisation code during the exchange and stops there. Once tokens are issued they are ordinary bearer credentials, usable by anyone who obtains them. Short lifetimes, refresh token rotation, working revocation, and sender-constrained tokens through DPoP or mutual TLS are what protect the tokens themselves.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.