A contractor opens a fictional municipal inspection app on a phone. The app sends them to the system browser to sign in. The city identity service redirects back with an authorization code. On a shared device, another application may be able to observe that redirect. If the code by itself can be exchanged for a token, the app that started the login is not the only app that can finish it.
OAuth public clients have this gap. A public client cannot keep a client secret, because the phone or the browser is not a confidential place to store one. RFC 7636 describes the authorization code interception attack against public clients that use the authorization code grant. It specifies Proof Key for Code Exchange, usually called PKCE. The client creates a one-time secret, proves it started the login, and only then exchanges the code.
Create a new verifier for each login
The client creates a code verifier for each authorization request. RFC 7636 requires a high-entropy cryptographic random string of unreserved characters, between 43 and 128 characters. It recommends taking 32 random octets and base64url-encoding them, which produces a 43-character verifier. The fictional inspection app generates that value when the contractor taps sign in, and it keeps the value only until this login attempt finishes or is abandoned. The next login gets a new verifier. Reusing an older value would turn a one-time proof into a longer-lived secret.
The app does not send the verifier in the first redirect. It sends a code challenge derived from it. When the client can use SHA-256, RFC 7636 says it must use the S256 method. The challenge is the base64url encoding of the SHA-256 hash of the ASCII verifier. The plain method, which uses the verifier itself as the challenge, is only for a client that cannot support S256 and already knows the server allows plain. A phone app that can hash should not choose plain. The challenge can travel through the browser. The verifier stays with the app.
Bind the challenge to the code, then demand the verifier
The authorization server must associate the code challenge and the challenge method with the authorization code it issues. The server must not send the challenge back to the client. When the inspection app later calls the token endpoint, it sends the authorization code and the original code verifier. The server transforms the verifier in the same way and compares it with the stored challenge. A match shows that the caller possesses the secret that started this login. An application that only captured the redirect has the code and still fails the comparison.
Store the verifier where the same app instance can read it when the redirect returns, and nowhere broader. A browser-based client should keep it in the tab or in storage that other origins cannot read. Do not put it in a query string, on a page that leaks through the referrer, or in a log line. The token request itself goes over TLS. The point of the RFC is that an attacker does not learn the verifier from the intercepted redirect, because the verifier was not on that redirect.
Keep PKCE separate from the other login checks
PKCE answers a narrow question: did the party exchanging the code also start this authorization request? It does not replace a check that the browser returned to the redirect the app registered. It does not replace the application's own session rules after a token exists. The fictional app still confirms the return address, and it still creates its own session only after the token response succeeds. Those are neighboring controls. Folding them into one informal security flag makes it hard to see which check failed.
The city identity service must actually enforce the comparison. A client that sends a challenge gains nothing if the token endpoint ignores a missing verifier. Confirm that behavior with a negative test. A code presented without the matching verifier is rejected. Confirm a positive test. The same app, with the verifier it stored, receives a token once. Confirm that a second login does not accept the first login's verifier.
Test the attempt before a contractor depends on it
Test a completed login on the phone. Test an abandoned login that never returns, and make sure the stored verifier expires with the attempt. Test two overlapping attempts by the same person, because a second tap must not overwrite the first verifier unless the first attempt is cancelled. Test that logs of the authorization redirect and of the token request do not contain the verifier. Test the S256 path specifically, not only a plain-method example copied from an older tutorial.
The result is a login that a shared device cannot finish with a code alone. The inspection app proves it is the same party that started the sign-in. The authorization code stops being sufficient by itself.
For related product work, see 4Minds Technology's mobile app development and custom software development. Write down where the verifier is stored, which challenge method is required, and how long an unfinished attempt may live.



