-
Notifications
You must be signed in to change notification settings - Fork 2.8k
refactor: extract OAuth helper functions and simplify provider state #1586
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
Conversation
040a546 to
81c470f
Compare
| raise OAuthRegistrationError(f"Invalid registration response: {e}") | ||
|
|
||
|
|
||
| async def handle_token_response_scopes( |
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.
based on the discussion, we’ll want to remove that check from the SDK
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.
removed
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.
cc: @pcarleton
6780800 to
fd612f2
Compare
pcarleton
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.
looks good, a few minor comments
pcarleton
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.
LGTM!
I did a brief look into other ways to allow using these methods outside of a generator (and also inside) that let us expose a higher level "discover Oauth info" interface.
The only other option seemed to be to have a state machine that has a "next request" method that output a request, but at least the quick sketch of it didn't seem very nice to use.
There might be something to explore on having an async generator specific to auth that is easier to use outside, but this seems like the best option for now
Refactors OAuth 2.0 authentication implementation to expose reusable utilities.
Motivation and Context
The OAuth authentication logic was tightly coupled to the httpx auth provider, making it difficult for external tools (like MCP proxies or custom clients) to reuse core OAuth functionality. This refactor extracts the OAuth primitives into standalone utilities that can be used independently.
Key improvements:
How Has This Been Tested?
Existing test suite updated to reflect new structure. All tests pass.
Breaking Changes
None - this is a pure refactor with no API changes.
Types of changes
Checklist
Additional context
New utilities added:
client/auth/utils.py: OAuth protocol helpers (discovery URLs, WWW-Authenticate parsing, scope selection, response handlers)shared/auth_utils.py: PKCE generation and token expiry calculationThe main OAuth2Auth provider (
client/auth/oauth2.py) now delegates to these utilities, reducing from 221 lines to 93 lines of core logic.