Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Response types, response modes, and older flows

An authentication request chooses what the authorization endpoint returns and how it delivers it. This lesson compares the response types and response modes on the collage app's sign-in for Ava, follows the older implicit and hybrid flows with the hash checks that protect them, and explains why code with PKCE is the default and how to move to it.

Two choices in one request

All domains, codes, and tokens in these examples are fictional. The hash values were calculated from the example values shown.

Every authentication request in this series has said response_type=code, and every response has come back in the query string of the collage app's callback. The authentication request noted what that meant: the ID token arrives later, in the direct token response, rather than in Ava Archer's browser address bar.

Those were deliberate choices, not the only ones available. Older integrations and some provider documentation use other values, and a provider that supports every combination lists them in its metadata like this:

"response_types_supported": ["code", "id_token", "id_token token",
    "code id_token", "code token", "code id_token token"],
    "response_modes_supported": ["query", "fragment", "form_post"]

An authentication request makes two separate choices about the response. The response type, in response_type, says what the authorization endpoint returns: a code, an ID token, an access token, or a combination. That decides which flow the sign-in follows and which tokens pass through the browser. The response mode, in response_mode, says how the authorization endpoint delivers its answer to the redirect URI.

Each response type comes with a default mode. For code, it is the query string. For every response type that returns a token from the authorization endpoint, including an ID token, the default is the fragment, and the query string must never be used. A request includes response_mode only to choose something other than the default, which is why the collage app's requests have never needed it.

Response type values combine with spaces, written as %20 in the request URL, and their order does not matter: code id_token and id_token code ask for the same thing. A provider compares them as a set of words, not as a string.

Response types and their flows

OpenID Connect uses six response types, and each selects one of three flows:

response_typeThe authorization endpoint returnsFlow
codeA codeAuthorization code
id_tokenAn ID tokenImplicit
id_token tokenAn ID token and an access tokenImplicit
code id_tokenA code and an ID tokenHybrid
code tokenA code and an access tokenHybrid
code id_token tokenA code, an ID token, and an access tokenHybrid

The implicit flow skips the token endpoint entirely. Everything arrives through the browser, so the provider never authenticates the client and issues no refresh token. The hybrid flow returns some values through the browser and then exchanges the code at the token endpoint as usual, which returns an access token and an ID token, just as in the code flow.

Plain token, the OAuth implicit grant, is missing from the table. It returns only an access token, and without an ID token there is no sign-in, so OpenID Connect does not use it. Why that grant existed and why it fell out of use is told in The implicit grant. OAuth also registers none, which returns no credentials at all and is rarely seen.

Three ways back

Whatever the response type, the answer reaches the redirect URI in one of three ways. To compare them, take the response from Following a complete sign-in and send it each way.

Query. The provider redirects to the redirect URI with the response in its query string, as every example so far has done. The browser requests that URL from the collage app's server, which reads the response directly. A URL travels further than the request it starts, though: into browser history, server and proxy logs, and the Referer header of requests the callback page makes. That is acceptable for a code, which is short-lived, works once, and is useless without the collage app's client authentication and PKCE verifier. It is not acceptable for a token, which is why tokens never use this mode.

Fragment. The response follows a # instead of a ?:

HTTP/1.1 302 Found
Location: https://collage.example/signin/callback#code=demo-code-12&state=demo-signin-3&iss=https%3A%2F%2Fauth.photos.example

Browsers do not send the fragment to the server. The collage app's server receives a request for /signin/callback with nothing attached, and only JavaScript running on the callback page can read the response, then use it in the page or pass it to the server. The fragment was designed for applications that ran entirely in the browser. It still lands in browser history, every script on the page can read it, and a browser carries it along when a later redirect does not set a fragment of its own. Redirect URI validation showed how that last behavior lets an open redirector forward tokens to another site.

Form post. With response_mode=form_post, defined in the OAuth 2.0 Form Post Response Mode specification, the provider does not redirect. It answers with a small HTML page whose form is addressed to the redirect URI and submitted automatically:

HTTP/1.1 200 OK
Content-Type: text/html;charset=UTF-8
Cache-Control: no-store

<html>
 <body onload="document.forms[0].submit()">
  <form method="post" action="https://collage.example/signin/callback">
   <input type="hidden" name="code" value="demo-code-12">
   <input type="hidden" name="state" value="demo-signin-3">
   <input type="hidden" name="iss" value="https://auth.photos.example">
  </form>
 </body>
</html>

Ava's browser then sends the response to the collage app as an ordinary form submission:

POST /signin/callback HTTP/1.1
Host: collage.example
Content-Type: application/x-www-form-urlencoded

code=demo-code-12&state=demo-signin-3&iss=https%3A%2F%2Fauth.photos.example

The code and state now travel in the request body, so they stay out of the callback URL, the browser history and the Referer header. They are not invisible: a server that logs request bodies, or a developer recording network traffic, can still capture them, so the collage app's logs record the outcome of the callback rather than its fields.

Form post also changes which cookies come back. The POST starts on the photo service's page, so to Ava's browser it is a cross-site request, and a cookie marked SameSite=Lax or Strict is not sent with it. If the collage app finds Ava's pending attempt through such a cookie, the callback arrives without it and the sign-in fails. The binding has to be arranged deliberately. One common choice is a separate short-lived cookie for the sign-in attempt, marked SameSite=None; Secure and limited to the callback path, which the callback still checks against state and the nonce. Another is to find the attempt on the server by state and then complete the sign-in after a same-site redirect, where the ordinary session cookie is present again. Many web frameworks also reject any form POST that lacks their own anti-forgery token, which the provider's page cannot include. The collage app exempts the callback alone, and that is safe only because the pending attempt, state, the expected issuer and the nonce and PKCE checks do the same job there.

Signed versions of these modes also exist, such as query.jwt and form_post.jwt, in which the provider signs the whole response as a JWT. The JWT Secured Authorization Response Mode (JARM) lessons in Advanced OAuth, beginning with Protecting an authorization response, cover them.

The implicit flow

You will still meet OpenID Connect integrations built on the implicit and hybrid flows, often in applications written before browsers could comfortably run the code flow with PKCE. OpenID Connect added protections to both flows, and to repair or replace these integrations you need to know what those protections cover and where they stop. To keep the comparison direct, imagine the collage app sending the sign-in from Following a complete sign-in in each of the older shapes, with the same attempt values.

An implicit sign-in asks for its tokens directly from the authorization endpoint:

https://auth.photos.example/authorize
  ?response_type=id_token%20token
  &client_id=photo-collage
  &redirect_uri=https%3A%2F%2Fcollage.example%2Fsignin%2Fcallback
  &scope=openid%20profile%20email
  &state=demo-signin-3
  &nonce=demo-nonce-3

There is no PKCE challenge, because there will be no code to exchange. The nonce, which a code-flow request may leave out, is required here. The response arrives in the fragment, with the ID token shortened for display:

https://collage.example/signin/callback
  #access_token=demo-access-token-12
  &token_type=Bearer
  &expires_in=600
  &id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6InBob3Rvcy1ycy0yMDI2LTA5IiwidHlwIjoiSldUIn0.eyJ...shortened
  &state=demo-signin-3
  &iss=https%3A%2F%2Fauth.photos.example

Compare that with the code flow. The collage app never authenticated, so its client secret played no part. Both tokens have passed through the address bar and remain in Ava's browser history, and only a script on the callback page can read them.

Because the ID token now arrives through the browser, the collage app validates it before believing anything in the response. state and iss find the pending attempt, then the signature, audience, lifetime and nonce are checked. The nonce is required in this flow, because nothing else ties the token to Ava's attempt. The access token beside it is tied to the ID token by the at_hash claim, which Checking c_hash and at_hash calculates. If the value does not match, the collage app discards the access token without calling any API with it. Nothing else could protect that token: there was no code exchange, so PKCE never came into play.

With response_type=id_token, no access token is issued at all, and so there is no at_hash. The claims that profile and email would have released through UserInfo are placed in the ID token instead, which turns that token into a description of Ava traveling in a URL.

The hybrid flow

The hybrid flow keeps the code exchange and adds tokens to the browser response. With response_type=code id_token, the response carries a code and an ID token, and combining it with response_mode=form_post delivers both straight to the server:

POST /signin/callback HTTP/1.1
Host: collage.example
Content-Type: application/x-www-form-urlencoded

code=demo-code-12
&id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6InBob3Rvcy1ycy0yMDI2LTA5IiwidHlwIjoiSldUIn0.eyJ...shortened
&state=demo-signin-3
&iss=https%3A%2F%2Fauth.photos.example

The body is split across lines for display. Decoded, the ID token's claims include one that the code flow's token did not:

{
  "iss": "https://auth.photos.example",
  "sub": "user-2048",
  "aud": "photo-collage",
  "iat": 1790845200,
  "exp": 1790845500,
  "auth_time": 1790845185,
  "nonce": "demo-nonce-3",
  "c_hash": "vF6ec9VXTnfCcMFxiT1V9Q"
}

Before it redeems the code, the collage app now has a signed statement of who signed in and, in c_hash, a way to tell that the code beside it is the one the provider issued with that statement.

So the collage app validates that first ID token completely, compares its c_hash with the code, and redeems the code only if both pass, still with its PKCE verifier and client authentication, which c_hash does not replace. The token endpoint then returns a second ID token. The collage app validates it fully as well and checks that its issuer and subject are the same as the first token's. Only then does it start a session or use the access token. If any step fails, the attempt ends there: a failed c_hash means the code is never redeemed, and a failed second token means nothing from the token response is used.

In the hybrid flow, one ID token arrives through the browser and another from the token endpoint. The collage app validates both and uses nothing until the second has passed.

Checking c_hash and at_hash

Both claims are calculated the same way, from the exact value that arrived in the response:

  1. Choose the hash function that matches the ID token's alg: SHA-256 for RS256, ES256, PS256, or HS256, and SHA-384 or SHA-512 for the algorithms that end in 384 or 512.
  2. Hash the ASCII bytes of the code or access token, as received after removing the URL or form encoding.
  3. Keep the left-most half of the hash, which is 16 bytes for SHA-256.
  4. Encode those bytes with Base64url, without padding, and compare the result with the claim exactly.

For the photo service's RS256 tokens, the calculation looks like this. The hashes are shown in hexadecimal and split at the halfway point, but the claim encodes the 16 bytes themselves, not their hexadecimal text:

ID token alg     RS256, so SHA-256

code             demo-code-12
SHA-256          bc5e9e73d5574e77c270c171893d55f5 392a9b5b318112b35490f46ea8fd57af
left-most half   bc5e9e73d5574e77c270c171893d55f5
c_hash           vF6ec9VXTnfCcMFxiT1V9Q

access token     demo-access-token-12
SHA-256          b5711f37490166d89c0612ba84ad867b c81049cd0ebe141cce00bb2b783ff79f
left-most half   b5711f37490166d89c0612ba84ad867b
at_hash          tXEfN0kBZticBhK6hK2Gew

Which claims must be present depends on what the authorization endpoint returned beside the ID token:

response_typec_hashat_hash
id_tokenNo code is returnedNo access token is issued
id_token tokenNo code is returnedRequired
code id_tokenRequiredNo access token in this response
code id_token tokenRequiredRequired

code token returns no ID token from the authorization endpoint, so there is nothing to compare until the token endpoint answers. In the code flow, an ID token from the token endpoint may also carry at_hash, and the relying party may check it in the same way.

A matching hash shows that the code or access token beside the ID token is the one the provider issued with it. With the signature and nonce checks, that defeats token substitution: an attacker cannot swap in a code or token from another session, because they cannot produce a signed ID token with this attempt's nonce and a matching hash. It says nothing about who else has seen the token, and a leaked access token still works at the photo API for anyone who holds it.

The common mistakes are small: hashing the encoded value instead of the decoded one, keeping the whole hash, using standard Base64 with +, /, and padding, or always using SHA-256 when the provider signs with ES384. Each produces a mismatch on a genuine response, and turning the check off in response removes the protection these flows depend on.

Why code is the default

With the code flow and PKCE, nothing that passes through the browser works on its own. The code needs the collage app's client authentication and the verifier from the pending attempt, both kept on the collage app's backend, and it works once. The tokens travel over a direct connection from the token endpoint, so they never appear in a URL, a history entry, or a page's scripts. The provider gets the chance to authenticate the client, to refuse a code presented twice, and to bind tokens to a key the client holds. None of that is possible for a token handed over in the browser.

Current OAuth security guidance draws its line at access tokens. Clients should not use response types that return an access token from the authorization endpoint: OAuth's plain token, and id_token token, code token, and code id_token token. The guidance names code id_token as an acceptable alternative, because access tokens still come from the token endpoint, and a hybrid integration that uses it with a form post is not insecure in itself. Even so, it puts a signed statement about the person into the browser and adds a second validation path and the hash checks, none of which the code flow needs. For a new relying party, code with PKCE does everything the other response types did, with less to get wrong.

That leaves the mode. The query string is the default and needs nothing extra. A form post keeps even the code out of URLs, history, and Referer headers, and current guidance names it as one way to reduce those leaks, at the cost of the cookie and framework arrangements above. The fragment offers a server-side relying party nothing, because its server cannot read the response without a script on the callback page to forward it. For the collage app, code with the default query mode remains a sound choice, and form_post is a reasonable step further where the provider supports it.

Moving to the code flow

Migrating older integrations, in the OAuth lessons on history, legacy, and migration, covers moving any client away from the implicit grant. A relying party has a few more things to carry across:

  • Change the request, keep the nonce. Send response_type=code with a fresh PKCE challenge, and keep sending and checking a nonce, which still ties the ID token to the attempt. Drop response_mode unless you deliberately choose form_post.
  • Move profile claims to UserInfo. A relying party that used response_type=id_token read the person's name and email from the ID token. With the code flow, those claims usually come from UserInfo, so the code that read them must call UserInfo and check its sub.
  • Replace silent renewal. Implicit applications often obtained new tokens by loading the authorization endpoint with prompt=none in a hidden frame, the technique Browser applications showed failing where third-party cookies are blocked. Use a refresh token protected as that lesson described, or a backend session.
  • Remove the old response types. Once the new flow is live, remove the implicit and hybrid response types from the client's registration so the provider refuses them. While they remain allowed, anyone can start a request that returns tokens to the old callback page, keeping any weakness there within reach.

The result is the sign-in the collage app has used throughout this series: one code in the query string or a form post, one ID token from the token endpoint, and nothing in the browser that works on its own.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

In a code id_token response, the ID token's c_hash does not match the code that arrived beside it. What should the collage app do? 1 of 4

Choose one answer.

The collage app switches to response_mode=form_post, and every sign-in now fails because no pending attempt is found. What is the most likely cause? 2 of 4

Choose one answer.

A relying party moves from response_type=id_token to the code flow with PKCE. Sign-in works, but its welcome page no longer shows people's names. What is the likely cause? 3 of 4

Choose one answer.

An older integration at the collage app uses a hybrid flow, and the team will keep one for now. Which response type does current OAuth security guidance accept? 4 of 4

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity