Skip to content

Accept httpx URL objects on OAuth client requests - #934

Open
gyanu2507 wants to merge 3 commits into
authlib:mainfrom
gyanu2507:httpx-url-objects
Open

Accept httpx URL objects on OAuth client requests#934
gyanu2507 wants to merge 3 commits into
authlib:mainfrom
gyanu2507:httpx-url-objects

Conversation

@gyanu2507

Copy link
Copy Markdown

httpx/httpx2 pass URL instances into get/request/stream. The Authlib wrappers forwarded those objects through as-is and they broke in places that expected a str.

str() them at the request/stream boundary on the async and sync OAuth2 and assertion clients.

Fixes #931

httpx/httpx2 pass URL instances around; request() and stream() were typed
and implemented against plain strings, so those objects failed at various
call sites. Coerce with str() before talking to the session.
Comment thread tests/clients/test_httpx/test_async_oauth2_client.py
It was dropped when the URL-object test was written in its place. The new
test now sits alongside it, and covers all three token placements so a URL
object is exercised on the body and uri paths too.

Co-authored-by: Cursor <cursoragent@cursor.com>
@gyanu2507
gyanu2507 requested a review from lepture August 31, 2026 08:31
@gyanu2507

Copy link
Copy Markdown
Author

@lepture the streaming test is back in 7ef220c, sitting next to the URL-object coverage rather than replacing it. Please take another look when you have a moment.

@calestyo

calestyo commented Sep 3, 2026

Copy link
Copy Markdown

Hey,...

In principle it might also be nice if authlib's other methods that take URLs (like create_authorization_url or fetch_token) would accept httpx.URL`.

But these do stuff like e.g. the in operator:
https://github.com/authlib/authlib/blob/v1.8.0/authlib/oauth2/client.py#L434-L440

which isn't supported by httpx.URL.

@gyanu2507

Copy link
Copy Markdown
Author

@calestyo agreed those other methods would be nicer with httpx.URL, but they are a different change.

request() only needed the URL as a request target. create_authorization_url / fetch_token do membership tests like url in self.token_endpoint (and similar string ops). httpx.URL does not support in, so accepting it there without first converting to str would raise.

I would keep this PR on the request path and do those helpers in a follow-up that stringifies (or wraps) before the in checks.

@calestyo

calestyo commented Sep 6, 2026

Copy link
Copy Markdown

Fine for me :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support httpx.URL objects for urls

3 participants