Skip to main content

Authorization Code

The Authorization Code grant (RFC 6749 §4.1) is the redirect-based flow OAuth 2.1 recommends for any application that signs in a real user. The client redirects the browser to ThunderID, the user authenticates on ThunderID-hosted pages, ThunderID redirects back with a short-lived authorization code, and the client exchanges that code for tokens at the token endpoint.

Authorization codes are single-use, bound to the redirect URI and client, and short-lived. They exist only to let a confidential client (or a public client using PKCE) collect tokens over a back-channel without exposing them to the browser.

How It Works

How ThunderID Implements It
AspectBehavior
Authorization endpointGET /oauth2/authorize
Token endpointPOST /oauth2/token
Response typecode only (implicit and hybrid response types are not supported)
Response modequery only. Omitted response_mode defaults to query; unsupported values such as fragment and form_post return invalid_request
PKCERequired for public clients (publicClient: true); recommended for confidential clients
Redirect URI matchingExact match against the application's registered redirect_uris
Redirect URI at token endpointRequired only when included in the authorization request (RFC 6749 §4.1.3); identical value enforced when present
state parameterRequired by RFC 6749 §10.12 / OAuth 2.1; the client must validate it on callback
iss in responseAlways included (see Issuer Identification)
Code lifetimeSingle-use, short TTL; binding to client + redirect_uri enforced on exchange
Refresh tokenIssued when refresh_token is in the application's grantTypes

Try It in ThunderID

The Authorization Code grant is the default for newly registered applications. Confirm or enable it on your application.

  1. Open Applications or Agents in the ThunderID Console and select your client.
  2. Open the Advanced Settings tab.
  3. Under Grant Types, ensure authorization_code is selected (add refresh_token to issue refresh tokens alongside).
  4. Add at least one Redirect URI.
  5. Save.

Run the Flow

# 1. Redirect the user to the authorization endpoint
https://thunderid.example.com/oauth2/authorize
?response_type=code
&client_id=$CLIENT_ID
&redirect_uri=https://app.example.com/callback
&scope=openid%20profile
&state=xyz
&code_challenge=$CODE_CHALLENGE
&code_challenge_method=S256

# 2. After sign-in, the authorization server redirects to:
# https://app.example.com/callback?code=...&state=xyz&iss=https://thunderid.example.com

# 3. Exchange the code for tokens
curl -X POST https://thunderid.example.com/oauth2/token \
-u "$CLIENT_ID:$CLIENT_SECRET" \
-d "grant_type=authorization_code" \
-d "code=$CODE" \
-d "redirect_uri=https://app.example.com/callback" \
-d "code_verifier=$CODE_VERIFIER"

The response_mode parameter is optional. For response_type=code, ThunderID uses query by default and returns the authorization response in the callback URL query string. Explicit response_mode=query is also accepted. Other response modes, such as fragment and form_post, return invalid_request.

Access tokens with permission scopes are bound to one resource server. Send resource=https://api.example.com/... on the authorization or token request when the client knows the target API, or configure defaultResourceServer for permission-bearing requests that omit resource. OIDC-only or scopeless requests without resource use the application's token.accessToken.defaultAudience, falling back to client_id.

Explore with AI

ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© Copyright Linux Foundation Europe.For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.