Skip to content

fix(chore): consolidate OIDC discovery + JWKS caching between sso_service and verify_credentials#4602

Open
bogdanmariusc10 wants to merge 5 commits intomainfrom
4133-chore-consolidate-oidc-discovery-jwks-caching-between-sso_service-and-verify_credentials
Open

fix(chore): consolidate OIDC discovery + JWKS caching between sso_service and verify_credentials#4602
bogdanmariusc10 wants to merge 5 commits intomainfrom
4133-chore-consolidate-oidc-discovery-jwks-caching-between-sso_service-and-verify_credentials

Conversation

@bogdanmariusc10
Copy link
Copy Markdown
Collaborator

🔗 Related Issue

Closes #4133


📝 Summary

Consolidates duplicate OIDC discovery and JWKS caching logic that existed in two separate modules into a single shared implementation.

Before: Identical OIDC discovery and JWKS client caching code existed in:

After: Single shared module mcpgateway/utils/oidc_discovery.py provides:

  • discover_oidc_metadata() with configurable success/negative TTL caching
  • get_jwks_client() for shared JWKS client caching
  • RFC 8414 + OIDC Discovery 1.0 support with trailing-slash normalization

Both callers now delegate to the shared module, eliminating ~143 lines of duplicate code.


🏷️ Type of Change

  • Bug fix
  • Feature / Enhancement
  • Documentation
  • Refactor
  • Chore (deps, CI, tooling)
  • Other (describe below)

🧪 Verification

Check Command Status
Lint suite make lint ✅ Pass
Unit tests make test ✅ Pass
Coverage ≥ 80% make coverage ✅ Pass

Test breakdown:


✅ Checklist

  • Code formatted (make black isort pre-commit)
  • Tests added/updated for changes
  • Documentation updated (if applicable)
  • No secrets or credentials committed

📓 Notes

Design decisions:

  1. Module location: Placed in mcpgateway/utils/ as it's a utility function used by multiple services, not business logic specific to one domain.

  2. Backward compatibility: Added re-exports in verify_credentials.py to maintain compatibility with existing test imports without requiring widespread test changes.

  3. Cache structure: Uses 3-tuple (timestamp, metadata, ttl) to support different TTLs for successful vs failed discovery attempts (300s success, 60s transient failure, 3600s permanent failure).

  4. RFC compliance: Implements both RFC 8414 (OAuth Authorization Server Metadata) and OIDC Discovery 1.0 endpoints with proper trailing-slash normalization per spec requirements.

  5. No behavior changes: Both auth paths (OAuth access tokens and SSO id_tokens) maintain identical behavior; only the implementation is consolidated.

Files changed:

…and verify_credentials

Closes #4133

- Extract shared module mcpgateway/utils/oidc_discovery.py with:
  - discover_oidc_metadata() with configurable success/negative TTL
  - get_jwks_client() for shared JWKS client caching
  - RFC 8414 + OIDC Discovery 1.0 support with trailing-slash normalization
- Update mcpgateway/utils/verify_credentials.py to delegate to shared module
- Update mcpgateway/services/sso_service.py to delegate to shared module
- Add comprehensive unit tests (16 new tests in test_oidc_discovery.py)
- Update existing tests to use shared cache references
- All 52 tests passing (16 new + 29 OAuth + 7 SSO)

Signed-off-by: Bogdan-Marius-Catanus <bogdan-marius.catanus@ibm.com>
@bogdanmariusc10 bogdanmariusc10 added the chore Linting, formatting, dependency hygiene, or project maintenance chores label May 5, 2026
@bogdanmariusc10 bogdanmariusc10 added the api REST API Related item label May 5, 2026
…aching-between-sso_service-and-verify_credentials
@bogdanmariusc10 bogdanmariusc10 force-pushed the 4133-chore-consolidate-oidc-discovery-jwks-caching-between-sso_service-and-verify_credentials branch from 9bc0c42 to 02113e2 Compare May 5, 2026 13:19
bogdanmariusc10 and others added 3 commits May 5, 2026 16:19
…aching-between-sso_service-and-verify_credentials
Signed-off-by: Bogdan-Marius-Catanus <bogdan-marius.catanus@ibm.com>
…aching-between-sso_service-and-verify_credentials
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api REST API Related item chore Linting, formatting, dependency hygiene, or project maintenance chores

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CHORE]: Consolidate OIDC discovery + JWKS caching between sso_service and verify_credentials

1 participant