Skip to content

Support nonce parameter in ID tokens#74

Merged
eswan18 merged 1 commit into
mainfrom
feat/nonce-support
Mar 31, 2026
Merged

Support nonce parameter in ID tokens#74
eswan18 merged 1 commit into
mainfrom
feat/nonce-support

Conversation

@eswan18
Copy link
Copy Markdown
Owner

@eswan18 eswan18 commented Mar 31, 2026

Summary

Implements OIDC nonce support per OIDC Core Section 3.1.2.1. When a client sends a nonce parameter in the authorization request, it is stored with the authorization code and included in the ID token. This allows clients to mitigate token injection attacks by verifying the nonce matches what they originally sent.

  • Fully backwards compatible: when nonce is not provided (the common case for all existing clients), the claim is omitted from the ID token via omitempty
  • Nonce flows through the full chain: authorize → login form → authorization code (DB) → token exchange → ID token claims
  • Also supported through the MFA flow (stored in auth_mfa_pending)

Changes

  • DB migration 000008: adds nullable nonce column to oauth_authorization_codes and auth_mfa_pending
  • SQL queries: updated InsertAuthorizationCode and CreateMFAPending to include nonce
  • Go code: threaded nonce through generateAuthorizationCode, generateTokens, writeTokenResponse, login handler, MFA handler
  • JWT: added Nonce field to IDTokenClaims
  • Template: added nonce hidden field to login form

Test plan

  • TestIDTokenIncludesNonce — sends nonce in authorize, verifies it appears in the ID token (written red/green TDD)
  • TestIDTokenOmitsNonceWhenNotProvided — verifies no nonce claim when not sent
  • Full regression: all 65+ tests pass

Closes #55.

🤖 Generated with Claude Code

When a client sends a nonce in the authorization request, it is now
stored with the authorization code and included in the ID token. This
allows clients to mitigate token injection attacks by verifying the
nonce matches what they originally sent.

The nonce flows through:
- authorize → login form (hidden field) → authorization code (DB)
- authorization code → token exchange → ID token claims
- MFA pending session also stores nonce for the MFA flow

Changes:
- Migration 000008: adds nonce column to oauth_authorization_codes and
  auth_mfa_pending
- Updated sqlc queries and regenerated code
- Added Nonce field to IDTokenClaims, LoginPageData
- Threaded nonce through generateAuthorizationCode, generateTokens,
  writeTokenResponse, and the login/MFA handlers
- Added nonce hidden field to login.html template

When nonce is not provided (the common case for existing clients), the
field is omitted from the ID token via omitempty — fully backwards
compatible.

Closes #55.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@eswan18 eswan18 merged commit 51c894a into main Mar 31, 2026
1 check passed
@eswan18 eswan18 deleted the feat/nonce-support branch March 31, 2026 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support nonce parameter in ID tokens (OIDC Core 3.1.2.1)

1 participant