-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Implement SEP-990 Enterprise Managed OAuth #1721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Implement SEP-990 Enterprise Managed OAuth #1721
Conversation
…naged Auth support. - Written unit test cases for client and server implementation of the enterprise managed auth code.
…/extensions/enterprise_managed_auth.py 232->235, 304->307. - Resolved pre-commit errors.
maxisbey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I was missing something,
| # ============================================================================ | ||
| # Data Models | ||
| # ============================================================================ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
| redirect_handler: Any = None, | ||
| callback_handler: Any = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these please be correctly typed
| token_data = { | ||
| "grant_type": "urn:ietf:params:oauth:grant-type:token-exchange", | ||
| "requested_token_type": self.token_exchange_params.requested_token_type, | ||
| "audience": self.token_exchange_params.audience, | ||
| "resource": self.token_exchange_params.resource, | ||
| "subject_token": self.token_exchange_params.subject_token, | ||
| "subject_token_type": self.token_exchange_params.subject_token_type, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be typed, either a BaseModel or a TypedDict. (@Kludex would you have a preference here?)
| # ============================================================================ | ||
| # Helper Functions | ||
| # ============================================================================ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
| Note: | ||
| For verification, use server-side validation instead. | ||
| """ | ||
| import jwt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to top of file
| # ============================================================================ | ||
| # Tests for TokenExchangeResponse | ||
| # ============================================================================ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
| # ============================================================================ | ||
| # Tests for IDJAGClaims | ||
| # ============================================================================ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
| # ============================================================================ | ||
|
|
||
|
|
||
| def decode_id_jag(id_jag: str, verify: bool = False) -> IDJAGClaims: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verify is unused
|
|
||
| **Example Usage:** | ||
|
|
||
| ```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this instead be put in the snippets folder and then use the scripts/update_readme_snippets.py script to update the README accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Need to explain how to use the access token once you get it.
- How does this work when the client ID is expired?
This PR implements the client-side components of SEP-990: Enterprise Managed Authorization. It introduces the
EnterpriseAuthOAuthClientProviderto handle the full token exchange flow required for Enterprise SSO, including RFC 8693 (Token Exchange) and RFC 7523 (JWT Bearer Grant).Motivation and Context
Implements: SEP-990
To support enterprise environments where direct API keys are not compliant, the Python SDK needs to support "Managed Authorization." This implementation allows the SDK to:
This aligns the Python SDK with the architecture defined in the SEP-990 implementation guide.
Implementation Details
The following components have been added to
src/mcp/client/auth/extensions/enterprise_managed_auth.py:TokenExchangeParametersandTokenExchangeResponseusing Pydantic to strictly type the exchange payloads.EnterpriseAuthOAuthClientProvider, which extends the baseOAuthClientProviderto orchestrate the exchange logic.urn:ietf:params:oauth:token-type:id-jagtoken types.How Has This Been Tested?
I have implemented comprehensive unit tests in
tests/client/auth/test_enterprise_managed_auth_client.pyusingpytestandunittest.mock.The testing suite covers the following scenarios:
Data Model Validation:
TokenExchangeParameterscorrectly generates requests for both OIDC ID Tokens (test_token_exchange_params_from_id_token) and SAML Assertions (test_token_exchange_params_from_saml_assertion).RFC 8693 Token Exchange Logic:
httpxto verify the correct payload structure (grant types, token types) is sent to the IdP.client_idandclient_secretare correctly injected into the request body when configured (test_exchange_token_with_client_authentication).RFC 7523 JWT Bearer Grant Logic:
Network Edge Cases:
httpx.ConnectError,httpx.ReadTimeout) to ensureOAuthTokenErroris raised with descriptive messages.Breaking Changes
No.
This is an additive extension. The core
OAuthClientProviderremains backward compatible. Only users specifically importing and usingEnterpriseAuthOAuthClientProviderwill be affected.Types of changes
Checklist
Additional context
pydanticfor model validation andhttpxfor async requests.src/mcp/client/auth/extensions/).