Skip to content

feat: Add OIDC discovery support for JWT validation - #513

Merged
JAORMX merged 1 commit into
mainfrom
feat/oidc-discovery-199
May 30, 2025
Merged

JAORMX merged 1 commit into
mainfrom
feat/oidc-discovery-199

Conversation

@JAORMX

@JAORMX JAORMX commented May 30, 2025

Copy link
Copy Markdown
Collaborator

Summary

Implements automatic JWKS URL discovery from OIDC well-known endpoints, making OIDC configuration significantly easier for users.

Changes

Core Implementation

  • OIDC Discovery Support: Added discoverOIDCConfiguration() function that automatically fetches OIDC configuration from the issuer's /.well-known/openid_configuration endpoint
  • Enhanced JWT Validator: Modified NewJWTValidator() to automatically discover JWKS URL when only the issuer is provided
  • New Error Types: Added ErrFailedToDiscoverOIDC and ErrMissingIssuerAndJWKSURL for better error handling
  • OIDC Discovery Document: Added OIDCDiscoveryDocument struct to parse the well-known endpoint response

Key Features

  • Backward Compatible: Existing code using explicit JWKS URLs continues to work unchanged
  • Automatic Discovery: When JWKS URL is not provided but issuer is, the system automatically discovers it
  • Precedence Logic: Explicit JWKS URL takes precedence over discovery
  • Robust Error Handling: Clear error messages for discovery failures
  • Security: Validates that discovered configuration contains required jwks_uri field

Usage Example

Before (required both issuer and JWKS URL):

thv run server-name \
  --oidc-issuer https://accounts.google.com \
  --oidc-audience my-app \
  --oidc-jwks-url https://www.googleapis.com/oauth2/v3/certs

After (JWKS URL auto-discovered):

thv run server-name \
  --oidc-issuer https://accounts.google.com \
  --oidc-audience my-app

Testing

  • Comprehensive Test Coverage: Added extensive tests covering OIDC discovery scenarios, integration tests, error handling, and edge cases
  • All Tests Pass: ✅ Unit tests, linting, and existing functionality verified
  • Backward Compatibility: ✅ Existing OIDC configurations continue to work

Fixes

Closes #199

Testing

  • Unit tests added and passing
  • Integration tests for end-to-end JWT validation with discovered JWKS
  • Error handling tests for various failure scenarios
  • Backward compatibility verified
  • Linting passes

Breaking Changes

None - this is a fully backward-compatible enhancement.

Implements automatic JWKS URL discovery from OIDC well-known endpoints.
This allows users to provide only the issuer URL and automatically
discover the JWKS URL, making OIDC configuration easier.

Features:
- Automatic discovery from /.well-known/openid_configuration
- Backward compatible with explicit JWKS URLs
- Comprehensive error handling and validation
- Extensive test coverage for all scenarios

Fixes #199
@JAORMX
JAORMX requested a review from amirejaz May 30, 2025 12:34
@JAORMX
JAORMX merged commit 5b5682d into main May 30, 2025
@JAORMX
JAORMX deleted the feat/oidc-discovery-199 branch May 30, 2025 13:31
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.

OIDC: Allow for determining JWKs from well known endpoint

2 participants