refactor: use context var and init whoami sample#8
Merged
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors exception naming and handling to use token-based terminology, integrates a context variable for storing authentication info, and updates the whoami sample accordingly. Key changes include replacing "JWT" exception names with "Token" exception names across tests and middleware, injecting a ContextVar for auth info in various functions and tests, and adjusting server sample and configuration to align with the new design.
Reviewed Changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/utils/create_verify_jwt_test.py | Updated test assertions and exception names to reflect token verification changes. |
| tests/middleware/create_bearer_auth_test.py | Refactored tests to inject and use a ContextVar for auth info and updated exception names and error messages. |
| tests/exceptions_test.py | Replaced JWT exception tests with token exception tests and updated expected messages. |
| tests/__init__test.py | Adjusted metadata and bearer auth middleware tests to use the new ContextVar parameter. |
| samples/server/whoami.py | Introduced a whoami tool sample that leverages the new context variable-based auth info. |
| samples/server/starlette.py | Removed sample file as part of the refactor. |
| pyproject.toml | Raised the minimum Python version and updated dependency versions. |
| mcpauth/utils/_create_verify_jwt.py | Replaced JwtPayload usage and exception names, omitting expires_at from AuthInfo creation. |
| mcpauth/types.py | Updated AuthInfo fields (e.g., making client_id optional, scopes default empty) and added JwtPayload model. |
| mcpauth/middleware/create_bearer_auth.py | Modified to accept a ContextVar parameter and store auth info via the context variable rather than attaching it to the request state. |
| mcpauth/exceptions.py | Renamed JWT verification exception to token verification exception and updated descriptions accordingly. |
| mcpauth/config.py | Added the userinfo_endpoint field to AuthorizationServerMetadata. |
| mcpauth/init.py | Updated MCPAuth initialization to use the context variable for maintaining auth info. |
| .github/workflows/main.yml | Updated the Python version matrix. |
Files not reviewed (1)
- .python-version: Language not supported
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.
ContextVarto store per-request context