Skip to content

Commit c46e939

Browse files
committed
fix(client): improve garbage collection for oauth clients
1 parent 9188e21 commit c46e939

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

authlib/oauth1/client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,5 @@ def handle_error(error_type, error_description):
172172
raise ValueError(f'{error_type}: {error_description}')
173173

174174
def __del__(self):
175-
del self.session
175+
if self.session:
176+
del self.session

authlib/oauth2/rfc7521/client.py

+4
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,7 @@ def _refresh_token(self, data):
9090
'POST', self.token_endpoint, data=data, withhold_token=True)
9191

9292
return self.parse_response_token(resp)
93+
94+
def __del__(self):
95+
if self.session:
96+
del self.session

tests/clients/test_starlette/test_user_mixin.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from httpx import ASGITransport
23
from starlette.requests import Request
34
from authlib.integrations.starlette_client import OAuth
45
from authlib.jose import JsonWebKey
@@ -16,9 +17,9 @@ async def run_fetch_userinfo(payload):
1617
async def fetch_token(request):
1718
return get_bearer_token()
1819

19-
app = AsyncPathMapDispatch({
20+
transport = ASGITransport(AsyncPathMapDispatch({
2021
'/userinfo': {'body': payload}
21-
})
22+
}))
2223

2324
client = oauth.register(
2425
'dev',
@@ -27,7 +28,7 @@ async def fetch_token(request):
2728
fetch_token=fetch_token,
2829
userinfo_endpoint='https://i.b/userinfo',
2930
client_kwargs={
30-
'app': app,
31+
'transport': transport,
3132
}
3233
)
3334

@@ -110,9 +111,9 @@ async def test_force_fetch_jwks_uri():
110111
)
111112
token['id_token'] = id_token
112113

113-
app = AsyncPathMapDispatch({
114+
transport = ASGITransport(AsyncPathMapDispatch({
114115
'/jwks': {'body': read_key_file('jwks_public.json')}
115-
})
116+
}))
116117

117118
oauth = OAuth()
118119
client = oauth.register(
@@ -123,7 +124,7 @@ async def test_force_fetch_jwks_uri():
123124
jwks_uri='https://i.b/jwks',
124125
issuer='https://i.b',
125126
client_kwargs={
126-
'app': app,
127+
'transport': transport,
127128
}
128129
)
129130
user = await client.parse_id_token(token, nonce='n')

0 commit comments

Comments
 (0)