Skip to content

Commit

Permalink
Merge pull request #695 from MeggyCal/master
Browse files Browse the repository at this point in the history
Support httpx 0.28
  • Loading branch information
lepture authored Dec 20, 2024
2 parents 27fb1fd + 1d10ff3 commit bc55003
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions authlib/integrations/httpx_client/assertion_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def __init__(self, token_endpoint, issuer, subject, audience=None, grant_type=No
claims=None, token_placement='header', scope=None, **kwargs):

client_kwargs = extract_client_kwargs(kwargs)
# app keyword was dropped!
app_value = client_kwargs.pop('app', None)
if app_value is not None:
client_kwargs['transport'] = httpx.ASGITransport(app=app_value)

httpx.AsyncClient.__init__(self, **client_kwargs)

_AssertionClient.__init__(
Expand Down Expand Up @@ -61,6 +66,11 @@ def __init__(self, token_endpoint, issuer, subject, audience=None, grant_type=No
claims=None, token_placement='header', scope=None, **kwargs):

client_kwargs = extract_client_kwargs(kwargs)
# app keyword was dropped!
app_value = client_kwargs.pop('app', None)
if app_value is not None:
client_kwargs['transport'] = httpx.WSGITransport(app=app_value)

httpx.Client.__init__(self, **client_kwargs)

_AssertionClient.__init__(
Expand Down
10 changes: 10 additions & 0 deletions authlib/integrations/httpx_client/oauth1_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def __init__(self, client_id, client_secret=None,
force_include_body=False, **kwargs):

_client_kwargs = extract_client_kwargs(kwargs)
# app keyword was dropped!
app_value = _client_kwargs.pop('app', None)
if app_value is not None:
_client_kwargs['transport'] = httpx.ASGITransport(app=app_value)

httpx.AsyncClient.__init__(self, **_client_kwargs)

_OAuth1Client.__init__(
Expand Down Expand Up @@ -87,6 +92,11 @@ def __init__(self, client_id, client_secret=None,
force_include_body=False, **kwargs):

_client_kwargs = extract_client_kwargs(kwargs)
# app keyword was dropped!
app_value = _client_kwargs.pop('app', None)
if app_value is not None:
_client_kwargs['transport'] = httpx.WSGITransport(app=app_value)

httpx.Client.__init__(self, **_client_kwargs)

_OAuth1Client.__init__(
Expand Down
10 changes: 10 additions & 0 deletions authlib/integrations/httpx_client/oauth2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def __init__(self, client_id=None, client_secret=None,

# extract httpx.Client kwargs
client_kwargs = self._extract_session_request_params(kwargs)
# app keyword was dropped!
app_value = client_kwargs.pop('app', None)
if app_value is not None:
client_kwargs['transport'] = httpx.ASGITransport(app=app_value)

httpx.AsyncClient.__init__(self, **client_kwargs)

# We use a Lock to synchronize coroutines to prevent
Expand Down Expand Up @@ -177,6 +182,11 @@ def __init__(self, client_id=None, client_secret=None,

# extract httpx.Client kwargs
client_kwargs = self._extract_session_request_params(kwargs)
# app keyword was dropped!
app_value = client_kwargs.pop('app', None)
if app_value is not None:
client_kwargs['transport'] = httpx.WSGITransport(app=app_value)

httpx.Client.__init__(self, **client_kwargs)

_OAuth2Client.__init__(
Expand Down
4 changes: 2 additions & 2 deletions tests/clients/test_httpx/test_async_oauth2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from unittest import mock
from copy import deepcopy

from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport

from authlib.common.security import generate_token
from authlib.common.urls import url_encode
Expand Down Expand Up @@ -96,7 +96,7 @@ async def test_add_token_to_streaming_request(assert_func, token_placement):
token_placement="header",
app=AsyncMockDispatch({'a': 'a'}, assert_func=assert_token_in_header)
),
AsyncClient(app=AsyncMockDispatch({'a': 'a'}))
AsyncClient(transport=ASGITransport(app=AsyncMockDispatch({'a': 'a'})))
])
async def test_httpx_client_stream_match(client):
async with client as client_entered:
Expand Down

0 comments on commit bc55003

Please sign in to comment.