Skip to content

Conversation

@developerkunal
Copy link
Contributor

@developerkunal developerkunal commented Nov 21, 2025

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

🔧 Changes

This PR migrates JWT handling from go-jose v2 to lestrrat-go/jwx v3 and refactors JWKS provider to use pure options pattern.

JWT Library Migration

  • Migrated from gopkg.in/go-jose/go-jose.v2 to github.com/lestrrat-go/jwx/v3
  • Updated all JWT parsing, validation, and JWKS handling to use jwx v3 APIs
  • Improved performance with jwx's native JWKS caching support

Pure Options Pattern for JWKS Provider

  • Refactored jwks.NewProvider() and jwks.NewCachingProvider() to pure options pattern
  • Changed all configuration to functional options (no positional parameters)
  • Added comprehensive option validation with clear error messages

New Options API:

  • WithIssuerURL(*url.URL) - required, sets the issuer URL for OIDC discovery
  • WithCustomJWKSURI(*url.URL) - optional, bypasses discovery and uses custom JWKS endpoint
  • WithCustomClient(*http.Client) - optional, uses custom HTTP client
  • WithCacheTTL(time.Duration) - CachingProvider only, sets cache TTL (default: 15 minutes)
  • WithCache(Cache) - CachingProvider only, uses custom cache implementation

Bug Fixes

  • Fixed race condition in JWKS caching with proper lock synchronization
  • Added URL validation to validator.WithIssuers for consistency with WithIssuer

Testing & Examples

  • Improved test coverage: jwks 92.1%, validator 87.0%
  • Added comprehensive tests for all 14 signature algorithms
  • Updated http-example and http-jwks-example to use new API
  • Documented pre-existing test failure in http-jwks-example with skip annotation

Breaking Changes

  • jwks.NewProvider() and jwks.NewCachingProvider() now return (*Provider, error) instead of *Provider
  • All provider configuration must use functional options

Migration Example:

// Before (v2)
provider := jwks.NewCachingProvider(issuerURL, 5*time.Minute)

// After (v3)
provider, err := jwks.NewCachingProvider(
    jwks.WithIssuerURL(issuerURL),
    jwks.WithCacheTTL(5*time.Minute),
)
if err != nil {
    log.Fatal(err)
}

📚 References

Part of v3 refactoring series:

  • Builds on PR 1.3: validator pure options pattern
  • Next: TBD

🔬 Testing

All tests pass with race detection:

go test ./validator -race -cover  # 87.0% coverage
go test ./jwks -race -cover       # 92.1% coverage
go test ./examples/http-example -v
go test ./examples/http-jwks-example -v

Manual Testing:

  1. Run http-example: cd examples/http-example && go run main.go
  2. Run http-jwks-example: cd examples/http-jwks-example && go run main.go
  3. Both examples demonstrate new options API

Replaces go-jose with lestrrat-go/jwx v3.0.12 for JWT operations and introduces improved issuer, audience and JWKS handling.

Major changes:

- Replace go-jose with lestrrat-go/jwx v3.0.12 for JWT handling

- Add ES256K algorithm support (ECDSA with secp256k1 curve)

- Implement multi-issuer support through WithIssuer and WithIssuers

- Simplify JWKS provider using jwx's built-in cache which reduces code size by about sixty percent

- Add manual issuer and audience validation to support multiple values

Status:

- Validator and JWKS packages build successfully

- Eighteen of twenty-eight validator tests are passing which confirms that all successful validation paths work

- Ten tests require updates to expected error messages and are currently in progress
…test coverage

  - Refactor jwks.NewProvider() and jwks.NewCachingProvider() to pure options pattern
  - Remove positional parameters, all configuration via functional options
  - Implement runtime type switching to accept both ProviderOption and CachingProviderOption
  - Fix race condition in cache implementation with proper lock synchronization
  - Add URL validation to validator.WithIssuers() for consistency
  - Improve test coverage: jwks 92.1% (+4.8%), validator 87.0% (+5.2%)
  - Add comprehensive tests for all signature algorithms (EdDSA, HS256/384/512, RS256/384/512, ES256/384/512/ES256K, PS256/384/512)
  - Update examples/http-jwks-example to use pure options API
  - Document and skip pre-existing test failure in http-jwks-example

  Breaking Changes:
  - NewCachingProvider now accepts options only (no positional params)
  - WithIssuers now validates URL format and returns errors for invalid URLs

  Fixes:
  - Race condition in jwxCache.Get() with concurrent goroutines
  - Missing URL validation in WithIssuers option

  All tests pass with race detection enabled.
@developerkunal developerkunal requested a review from a team as a code owner November 21, 2025 12:28
@developerkunal developerkunal changed the title refactor: migrate to jwx v3 and implement pure options for JWKS provider refactor: PR 1.4 migrate to jwx v3 and implement pure options for JWKS provider Nov 21, 2025
@codecov-commenter
Copy link

codecov-commenter commented Nov 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.46%. Comparing base (7cf5d00) to head (1da96e0).

Additional details and impacted files
@@                         Coverage Diff                         @@
##           v3-phase1-pr3-validator-options     #358      +/-   ##
===================================================================
+ Coverage                            97.95%   99.46%   +1.50%     
===================================================================
  Files                                   13       13              
  Lines                                  441      562     +121     
===================================================================
+ Hits                                   432      559     +127     
+ Misses                                   6        3       -3     
+ Partials                                 3        0       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants