fix(chore): consolidate OIDC discovery + JWKS caching between sso_service and verify_credentials#4602
Open
bogdanmariusc10 wants to merge 5 commits intomainfrom
Conversation
…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>
Open
5 tasks
…aching-between-sso_service-and-verify_credentials
9bc0c42 to
02113e2
Compare
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 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:
mcpgateway/utils/verify_credentials.py(OAuth access token verification for MCP endpoints)mcpgateway/services/sso_service.py(SSO id_token verification during interactive login)After: Single shared module
mcpgateway/utils/oidc_discovery.pyprovides:discover_oidc_metadata()with configurable success/negative TTL cachingget_jwks_client()for shared JWKS client cachingBoth callers now delegate to the shared module, eliminating ~143 lines of duplicate code.
🏷️ Type of Change
🧪 Verification
make lintmake testmake coverageTest breakdown:
tests/unit/mcpgateway/utils/test_oidc_discovery.pytests/unit/mcpgateway/test_auth.py(updated mock references)tests/unit/mcpgateway/services/test_sso_service.py(updated cache references)✅ Checklist
make black isort pre-commit)📓 Notes
Design decisions:
Module location: Placed in
mcpgateway/utils/as it's a utility function used by multiple services, not business logic specific to one domain.Backward compatibility: Added re-exports in
verify_credentials.pyto maintain compatibility with existing test imports without requiring widespread test changes.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).RFC compliance: Implements both RFC 8414 (OAuth Authorization Server Metadata) and OIDC Discovery 1.0 endpoints with proper trailing-slash normalization per spec requirements.
No behavior changes: Both auth paths (OAuth access tokens and SSO id_tokens) maintain identical behavior; only the implementation is consolidated.
Files changed:
mcpgateway/utils/oidc_discovery.py(223 lines)tests/unit/mcpgateway/utils/test_oidc_discovery.py(289 lines)mcpgateway/utils/verify_credentials.py(-143 lines, +11 lines)mcpgateway/services/sso_service.py(-49 lines, +8 lines)tests/unit/mcpgateway/test_auth.py(1 line mock update)tests/unit/mcpgateway/services/test_sso_service.py(3 tests updated)