Understanding the step-by-step interaction between the client, authorization server, and resource owner is essential for implementing secure web authorizations. This article breaks down the core flow diagram and highlights key parameters like code_verifier and code_challenge that protect against interception attacks.
Scenario: A Mobile App Requesting User Data
This is a hypothetical scenario: a developer at a small photo-sharing project is sketching the authorization-code handoff for its mobile client before writing any code. The client wants a display name, an email address, and a list of albums, and the page being drafted is a single flow description with a compact parameter table beneath it.
The drawn sequence has four stops. First, the app opens a browser view toward the authorization endpoint at auth.example-service.test on the path /oauth/authorize, carrying the query keys response_type, client_id, redirect_uri, scope, and state. Second, the authorization service returns the browser to the registered custom scheme, whose path is /callback, with code and state. Third, the app's backend, not the app itself, posts to the token endpoint at auth.example-service.test on the path /oauth/token with grant_type, code, redirect_uri, client_id, and client_secret. Fourth, the backend calls the user-info endpoint with the access token in the Authorization request header and renders the three fields it needs.
The parameter table the developer drafts uses four columns: Name, Where it appears, Example value, and Why it matters. Two fictional rows show how entries are classified. The row for redirect_uri sits in the authorization request and the token request, its example reads the custom-scheme callback path above, and its note says the two values must match exactly. The row for state sits in the authorization request and the callback, its example is a short random string recorded per attempt, and its note says the app compares the returned value before exchanging the code.
One choice deserves an explicit example. The developer first writes scope as profile email albums, then narrows the draft to profile email and leaves albums for a later screen. The reason recorded in the margin is that album listing is only needed after the user reaches the library view, so asking at sign-in would widen the consent screen for no immediate gain. The client_id and client_secret in the table are placeholder strings the developer made up for this sketch, and the host names are invented for the drawing as well; nothing here claims a working registration or a completed run.
Step-by-Step Breakdown of the Standard Authorization Flow
You can start by turning your own sequence sketch into a short written walkthrough before touching any code, so each handoff has a sentence you can check. Take the four stops from your drawing and write, in plain language, what the client sends, what the authorization server returns, and what the browser hands back at each stop. A useful first line might read: "The client opens a browser view to the authorization endpoint and includes the client identifier, requested scopes, redirect target, and a state value." Note down, for each sentence, which of your draft parameters appears and where — query, request body, or response — so the description and the table stay in step.
Your parameter table can hold four columns: Name, Where it appears, Example value, and Why it matters. For a fictional entry, you might record "scope — query parameter — profile email — limits what the resource owner is asked to approve." Consider drafting the table first and then writing the prose against it; that order tends to expose gaps, such as a parameter you mention in the sequence but never explain. You can also reverse one row at a time and ask whether the sentence would still make sense if that value were missing.
Narrowing scope deserves its own worked example. Suppose you first wrote profile email albums, then reduced it to profile email to match what the client actually displays. Record both versions and one sentence on the trade-off: albums drops out of the consent request, so a later step that expects album data has no approval behind it. Keep this as your own hypothetical edit rather than a claim about any real service.
For the state value, you might write a before-and-after pair. Before: the redirect is described without any state. After: the sentence explains that state is generated by the client, carried through the redirect, and compared on return. Decide whether that comparison belongs in your flow description or in a separate note you keep beside it; either choice is defensible as long as you can point to where the check happens in your own sequence.
Before you finish the section, re-read the walkthrough against the table and mark any row that never appears in a sentence, or any sentence that mentions a value absent from the table. Those mismatches are the next edit, and resolving them leaves you with a flow description you can read end to end without guessing.
The Role of the Code Verifier in Securing the Exchange
RFC 7636 defines the code verifier as a high-entropy cryptographic random string using unreserved characters from A through Z, a through z, 0 through 9, and the characters hyphen, period, underscore, and tilde, with a minimum length of 43 characters and a maximum of 128. The specification recommends generating a 32-octet sequence with a suitable random number generator and base64url-encoding it into a 43-character URL-safe string.1
For the exchange, the client sends the code verifier to the token endpoint along with the authorization code. The authorization server transforms the code verifier and compares the result with the previously received code challenge; if they are not equal, access is denied. An attacker who intercepts the authorization code cannot redeem it for an access token without the code verifier.1
You can now return to your draft with one more pass: take the code verifier entry you have already listed and turn it into two or three sentences that sit beside the token-exchange stop in your sequence. Use your own placeholder values, and show where the verifier comes from and where it is presented. For a fictional example, you might write that the client generates an unpredictable string, keeps it locally, and later presents it at the token endpoint together with the authorization code; the sentence makes clear that the code alone is not enough to complete the exchange.
You might also record a short before-and-after pair for the parameter table. Before: a row that names code_verifier and gives only an example value. After: the row keeps the same example but adds a plain-language reason such as “proves the client that started this request is the one finishing it.” This keeps your earlier table layout and gives the new row a purpose a reader can compare with the code and scope rows.
Consider noting one choice you made rather than presenting it as a rule: whether your draft describes the verifier as generated for each authorization attempt or reused across attempts. Write the version you intend to depict and a sentence explaining your reason, so a later reader can see the assumption. You can then re-read the exchange paragraph against that row and adjust either one until the code, verifier, and resulting tokens are described in a consistent order.
Generating and Transmitting the Code Challenge
RFC 7636 describes the code challenge as derived from the code verifier using one of two transformations. For S256, the code challenge equals BASE64URL-ENCODE(SHA256(ASCII(code_verifier))). For plain, the code challenge equals the code verifier itself. The specification states that a client capable of using S256 MUST use S256, since S256 is Mandatory To Implement on the server; clients are permitted to use plain only if they cannot support S256 for some technical reason and know through out-of-band configuration that the server supports plain.1
The client then sends the code challenge as part of the OAuth 2.0 Authorization Request with two additional parameters. The code_challenge parameter is REQUIRED, while code_challenge_method is OPTIONAL and defaults to plain if not present in the request; its value is S256 or plain, identifying the transformation method.1
You can now move from your code verifier entry into the code challenge step by writing two or three sentences that sit directly beside it in your draft. One workable pattern: name the transform you intend to apply to the verifier, state that the challenge travels in the authorization request while the verifier stays with the client, and note when the verifier would be sent later. Treat those as sentences you are preparing to check against the protocol documentation, not as verified claims yet.
You might also add a short before-and-after pair for the table. Before: a row that names code_challenge and gives only an example value. After: the same row also records where the value appears and a brief reason it matters. If you are unsure which hash method your draft should assume, consider marking the method as an open question in your own notes rather than writing it as settled.
It can help to note one choice rather than presenting it as a rule: whether your draft describes the verifier as generated fresh for each authorization attempt or reused. Either way, keep the example values clearly fictional and your wording in the conditional, so the section reads as a plan you will confirm before implementation.
Server-Side Validation of the Transformed Secret
The draft should state the server-side comparison as RFC 7636 defines it: the authorization server transforms the code_verifier received at the token endpoint and compares it to the t(code_verifier), the code_challenge, recorded earlier when the authorization code was issued. Access is denied if the two values are not equal.1
The same document notes that when the server issues the authorization code, it must associate the code_challenge and code_challenge_method values with that code so they can be verified later. It also says the server must not include the code_challenge value in client requests in a form that other entities can extract, and that the exact association method is out of scope.1
You might take the code_challenge row you have already drafted and write a sentence beside it describing how the authorization code is later exchanged at the token endpoint, with the verifier presented there instead of the challenge. If your draft includes a fictional flow where the client sends the code to its own backend, a sentence can note that the verifier is kept server-side and used only in that exchange, so the challenge value alone appears in the earlier authorization request. Consider making this a labelled scenario rather than a stated rule, since the details of each deployment vary.
For the parameter table, a before-and-after pair can clarify the same point. Before: a row that names code_verifier and gives only an example value. After: the same row adds a short note that the verifier is submitted only when redeeming the code, while the derived challenge belongs to the earlier request. Keep the table compact and let the walkthrough carry the reasoning, so the two parts of your draft do not repeat each other.
You might also record one choice openly: whether the draft describes the verifier as generated fresh for each authorization attempt or as reused across attempts. Either can be written, but stating the choice helps a reader follow the rest of your example without guessing.
Common Pitfalls When Implementing Key Parameters
For the pitfalls section, you can work from the parameter table you have already drafted and give each weak row a short before-and-after revision. A fictional example: before, a scope row reads only "profile email albums" with no explanation. After, it reads "profile email — names the pieces the client wants; one entry per request, narrowed if any item is not needed for this handoff." The second version tells a reader why the value looks the way it does and what a writer should check before copying it.
A common pitfall is treating a parameter as self-explanatory. Take the redirect target row and add one sentence describing when the browser is sent there and what the client expects to receive on return. You might phrase it as: "The user is sent to this location after the decision; the client reads the returned value before continuing." If your table has a row whose "Why it matters" cell is blank or repeats the name, that is a cue to write the sentence before moving on.
Another pitfall is mixing draft choices with rules. You can mark one line as a choice, for example whether the verifier is described as fresh for each attempt or reused, and keep it visibly separate from the documented exchange step. Consider adding a short "open question" note beside that row instead of resolving it silently.
Finally, you can re-read the walkthrough and the table together once more. For each row, note in a margin whether it appears in at least one sentence of the flow. Rows that never surface, or sentences that mention a value absent from the table, are worth revising before you call the draft complete. This check stays with your own material and does not depend on any tool or external test.
Frequently asked questions
How can I turn my own sequence sketch into a written walkthrough before writing code?
You can start by turning your own sequence sketch into a short written walkthrough before touching any code, so each handoff has a sentence you can check. Take the four stops from your drawing and write, in plain language, what the client sends, what the authorization server returns, and what the browser hands back at each stop.
What four columns can I use in my parameter table?
Your parameter table can hold four columns: Name, Where it appears, Example value, and Why it matters. For a fictional entry, you might record "scope — query parameter — profile email — limits what the resource owner is asked to approve."
How can I check my walkthrough against my table before finishing the section?
Before you finish the section, re-read the walkthrough against the table and mark any row that never appears in a sentence, or any sentence that mentions a value absent from the table.