Join our Newsletter — 33% off our NHI Course
Home› Guides› PKCE for Beginners: How a Secret Word Stops…
Guide Authentication

PKCE for Beginners: How a Secret Word Stops Stolen Sign-In Codes Being Used

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 28 November 2026 11 min read
On this page

PKCE is an extra check that stops a stolen one-time sign-in code being used by the wrong app.

This guide is for students, newcomers to IT and anyone who has seen "PKCE" in app settings or a developer's notes. You do not need to write code: if your business has a phone app or website with a "Sign in with" button, PKCE is one of the checks that keeps those sign-ins safe.

In short

  • When you use a "Sign in with" button, the app gets a short-lived one-time code, then swaps it for a token.
  • PKCE makes the app keep a secret word and prove it knows that word when it swaps the code.
  • Someone who copies the code but not the secret word should be refused.
  • Current OAuth security advice says apps on phones, computers and in browsers must use PKCE, and recommends it for every app.

What you will learn

  • Explain what PKCE does in one sentence.
  • Spot the two PKCE parts in a sign-in request.
  • Explain why a stolen code alone should not be enough.
  • Ask your developers or suppliers whether your apps use PKCE.
One-time sign-in code (authorisation code)
a short-lived code an app receives after you sign in, which it swaps for a token.
Access pass (access token)
a digital pass that lets an app reach your data for a limited time.
Secret word (code verifier)
a random value the app makes and keeps, then shows when it swaps the code.

What is PKCE?

Think of ordering a parcel to collect from a shop. When you order, you give the shop a scrambled version of a secret word. When you collect, you must say the word itself.

PKCE works the same way for apps. It stands for Proof Key for Code Exchange, and people often say it as "pixy".[1] It is an add-on to OAuth, the system behind most "Sign in with" and "Connect your account" buttons.

When you sign in, the sign-in service gives the app a one-time code (an authorisation code). The app then swaps that code for an access token, the pass it really needs. PKCE adds one rule to the swap. The app must also show the secret word it made at the start, called the code verifier.

Where the comparison stops working: a shop assistant might accept a good excuse. A sign-in service checks the word by maths, so a guess or a near miss should not pass.

Why does it matter?

The one-time code travels through your phone or browser, where other apps or add-ons may get a look at it. PKCE was written to stop a rogue app that grabs the code from using it.[1] Without it, whoever swaps the code first may get the token.

If your business has its own app

What could happen: a rogue app on a customer's phone grabs a sign-in code and gets into their account.

Check this: ask your app supplier, in writing, whether every sign-in uses PKCE.

Next: OAuth 2.0 for Beginners

If you are learning to build apps

What could happen: you copy an old tutorial that skips PKCE, and your app's sign-in is easier to abuse.

Check this: use a well-known sign-in library and confirm PKCE is switched on.

Next: Access and Refresh Tokens for Beginners

If you review or buy software

What could happen: you approve an app that sends sign-in codes without any extra check.

Check this: add "uses PKCE with the S256 method" to your security questions for suppliers.

Next: Client Secret vs PKCE

What does it look like?

You will not normally see PKCE, because it happens in the background. Here is a made-up sign-in request and the later swap. The PKCE parts are marked.

Example only. All values are made up.

# 1. The app asks to sign you in
https://login.example.invalid/authorize
  ?client_id=EXAMPLE-SHOP-APP
  &code_challenge=FAKE-SCRAMBLED-0000    (1)
  &code_challenge_method=S256           (2)

# 2. Later, the app swaps the code
code=EXAMPLE-ONE-TIME-CODE-0000          (3)
code_verifier=FAKE-SECRET-WORD-0000      (4)
  1. The scrambled copy of the secret word, called the code challenge. It is safe to send at the start.
  2. The scrambling method. S256 means the word was put through a one-way maths function.
  3. In a real message, this line would contain the one-time code from the sign-in service.
  4. In a real message, this line would contain the secret word, sent only in the final swap.

Why this is risky: without PKCE, lines (1), (2) and (4) are missing. Then the code in line (3) is all anyone needs.

The safer way: the app makes a fresh secret word for every sign-in and uses the S256 method. The standard says apps that can use S256 must do so.[1]

How does it work?

  1. Make a secret word. Before sign-in starts, the app creates a long random value, the code verifier, and keeps it to itself.[1]
  2. Send a scrambled copy. It scrambles the word with a one-way maths function and sends that copy, the code challenge, with the sign-in request.
  3. You sign in. You sign in at the real service. It remembers the scrambled copy and sends the app a one-time code.
  4. Swap the code. The app sends the code and the original secret word to the sign-in service.
  5. Check the match. The service scrambles the word itself. If the result matches what it stored, it issues the token. If not, it should refuse.[1]
Five step diagram titled How PKCE ties the one-time code to the app that asked. Step 1, Secret word: the app makes a random secret word and keeps it. Step 2, Scrambled: it sends a scrambled copy with the request. Step 3, You sign in: the sign-in service sends back a one-time code. Step 4, Swap: the app sends the code plus the secret word. Step 5, Match check: the service checks the word matches the scrambled copy. A dashed note says someone who copies the code in step 3 does not have the secret word from step 1. A green bar says no match, no token: the stolen code on its own should be refused.
Figure 1. The secret word stays with the app, so only the app that started the sign-in can finish it.

The scrambling is one-way. Seeing the scrambled copy does not give away the secret word, so the copy can travel openly while the word stays hidden until the end.

Two panel diagram titled A stolen one-time code, with and without PKCE. Left panel, Without PKCE: a rogue app copies the one-time code, it swaps the code at the sign-in service, and the service hands over a token to your account. Right panel, With PKCE: a rogue app copies the one-time code, it tries to swap the code but has no secret word, and the service sees no match and refuses. A green bar says PKCE protects the code; look after tokens separately once they are issued.
Figure 2. The same stolen code, with and without the PKCE check.

PKCE was first written for phone apps in 2015. A 2025 update to OAuth security advice covers this. It says public clients must use it. These are apps on phones, computers and in browsers, which cannot hide a stored password. It recommends PKCE for server-based apps too.[2]

A worked example

Quinn Varga runs a small fictional cycling club. The club has a phone app where members sign in with their email provider's "Sign in with" button to book rides.

A member, Leila Whitlock, reports something odd. She installed a free "ride tracker" app from outside the official app store. Since then, a pop-up has appeared during sign-in to the club app.

Quinn thinks of the parcel shop. If a stranger picks up the collection slip, can they take the parcel? It depends on whether the shop asks for the secret word.

Quinn asks the club's freelance developer, Uma Ulrich, how sign-in works. Uma checks the settings. The app uses a well-known sign-in library, and PKCE with the S256 method is switched on. A copied one-time code should be refused without the secret word.

Uma also checks the sign-in service's records for Leila's account. She sees no sign-ins from unknown devices in the records available to her. As a precaution, she signs Leila out of every device, so old tokens should no longer give access.

Leila deletes the ride tracker app and runs her phone's security check. Quinn adds a line to the club newsletter: only install apps from the official stores.

Last, Quinn asks Uma to put "PKCE on, S256 only" into the app's written setup notes, so the next developer keeps it.

Myths and mistakes

What people thinkWhat is true
PKCE is only for phone apps.It started there, but current advice says browser and desktop apps must use it too, and recommends it for server-based apps.[2]
Hiding a password inside the app does the same job.Anything stored in an app on a phone or in a browser can be pulled out. PKCE uses a fresh secret for every sign-in instead.
Any PKCE setting will do.The "plain" method sends the secret word unscrambled. Use S256 wherever it is available.[2]
PKCE protects my tokens too.PKCE protects the one-time code. Tokens need their own care once they are issued, such as short lifetimes and signing out old devices.
We can reuse one secret word to save effort.Each sign-in should get a new, random secret word. A reused word gives a thief more chances.[1]

What can I do this week?

  • List the apps and websites your organisation runs that have a "Sign in with" button.
  • Ask each developer or supplier: "Does every sign-in use PKCE with S256?"
  • Check that your sign-in service is set to require PKCE, if it offers that setting.
  • Remind staff and customers to install apps only from official app stores.

Checklist

  • Every app with a "Sign in with" button uses PKCE.
  • The S256 method is used, not "plain".
  • A new secret word is made for every sign-in.
  • The sign-in service refuses a swap with a missing or wrong secret word.
  • Apps use a well-known, up-to-date sign-in library rather than home-made code.
  • Supplier security questions ask about PKCE.
  • Tokens are short-lived and can be cancelled by signing out devices.

Common questions

Is PKCE the same as two-factor sign-in?

No. Two-factor sign-in checks the person, for example with a code on your phone. PKCE checks the app, making sure the app that finishes a sign-in is the one that started it. You can, and often should, have both working at the same time.

Do I need to do anything as a user?

Usually not. PKCE runs in the background inside the app and the sign-in service. Your part is to install apps from official stores, keep them updated and sign out devices you no longer use. The setup work falls to the people who build and run the app.

Does an app with a client secret still need PKCE?

Yes, current advice recommends it. A client secret proves which app is calling. PKCE proves the code belongs to this one sign-in. They guard against different problems. The practitioner guide Client Secret vs PKCE explains why.

Why is the scrambled copy safe to send?

Because the scrambling only works one way. The S256 method runs the secret word through a maths function that is easy to do but very hard to reverse. Seeing the scrambled copy does not reveal the word that the app shows at the end.

Does PKCE apply to software that talks to software with no person signing in?

No. PKCE protects the one-time code in a sign-in where a person takes part. Programs that connect on their own, such as a nightly reporting job, prove who they are in other ways. Those programs are non-human identities (NHIs), and they need their own care.

Where next?

Ready for the detail? Read the practitioner guide: Client Secret vs PKCE. It goes further into why server-based apps need both checks, the stronger ways for apps to prove who they are, and how to roll both out.

Also useful:

Related NHI Mgmt Group resources: Consent Phishing and Illicit OAuth Grants Guide · How to detect use of a stolen OAuth refresh token

Key terms

PKCE
An extra check that ties a one-time sign-in code to the app that asked for it.
OAuth
A standard way to let an app use some of your data at another service without giving it your password.
Access token
A short-lived digital pass that lets an app reach data or a service on your behalf.
Code verifier
A random secret an app creates at the start of a sign-in and reveals only when it swaps the one-time code.
Code challenge
A scrambled copy of the code verifier sent at the start of a sign-in, used later to check the match.
Public client
An app that runs on a device people control, such as a phone app or browser app, so it cannot keep a stored password secret.
Redirect URI
The address the sign-in service sends you back to, carrying the one-time code.

Sources and further reading

  1. RFC 7636: Proof Key for Code Exchange by OAuth Public Clients. IETF, September 2015. https://www.rfc-editor.org/rfc/rfc7636, accessed 28 Nov 2026.
  2. RFC 9700: Best Current Practice for OAuth 2.0 Security (BCP 240). IETF, January 2025. https://www.rfc-editor.org/rfc/rfc9700, accessed 28 Nov 2026.

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.