Skip to content
engineering workbench.by StudyPort Academy
Learning path
Intermediate18 min

OAuth and sign in with X

Understand the idea

The user signs in at the other site. Your app receives a code, not their password.

The idea

is that delegation. The user authenticates at the identity provider. Your app never sees the password. The old implicit flow for browser apps sent the access token back in the URL fragment, after the hash. Fragments land in browser history, they can leak through Referer when a page loads a third-party resource, and an open redirect can send the whole URL to an attacker. The token is then just a string they replay. replaced that for browser and mobile apps. The client creates a verifier, sends only the SHA-256 challenge when it starts the login, and later posts the code plus the original verifier to the token endpoint. The token comes back in the response body. The front-channel URL in the run contains code=code-1 and does not contain access_token. A stolen code without the verifier fails the hash compare.

What changes

Why PKCE replaced the implicit flow
Old approachWeakness that showed upWhat replaced it
Implicit flow: access token in the URL fragmentThe token is in a URL. Browser history, the Referer header, and a malicious or open redirect can all capture it. Whoever has the string can call the API.PKCE. The front channel carries an authorization code. The client proves it with a verifier it created up front, and the token is returned on a back-channel POST, never in the URL.

The command

Fragment leak versus a back-channel exchange

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

The mistake

Check the result

The implicit line includes access_token=secret-token. The front channel line is false. The body line is secret-token, which never appeared in the front-channel URL.

Guided challenge

Require the verifier

exchange currently returns the token for any code that exists. Put the SHA-256 compare back so a wrong verifier is rejected. The matching verifier should still print body token secret-token.

Require the verifier

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

EXPECTED RESULT

stolen bad verifier
body token secret-token

Hints 0/2

    Use all hints or make 3 failed checks (0/3).

    Free exploration

    Change this example and run it again. Each run is a new process. Nothing is saved.

    Your variation

    3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01What did the implicit flow put in the browser URL?
    02What does PKCE send on the front channel?

    Ready to call this one understood?

    Mark this lesson complete to earn 150 XP. You can always revisit it.

    Sign in to save progress
    Next lesson