Skip to content

Commit b9cd222

Browse files
committed
fix after rebase
1 parent dbd801d commit b9cd222

File tree

10 files changed

+189
-109
lines changed

10 files changed

+189
-109
lines changed

src/auth/src/supabase_auth/_async/gotrue_admin_api.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ async def update_user_by_id(
171171
Never expose your `service_role` key in the browser.
172172
"""
173173
validate_uuid(uid)
174+
response = await self._request(
174175
"PUT",
175176
f"admin/users/{uid}",
176177
body=attributes,
@@ -193,6 +194,7 @@ async def _list_factors(
193194
params: AuthMFAAdminListFactorsParams,
194195
) -> AuthMFAAdminListFactorsResponse:
195196
validate_uuid(params.get("user_id"))
197+
response = await self._request(
196198
"GET",
197199
f"admin/users/{params.get('user_id')}/factors",
198200
)
@@ -204,6 +206,7 @@ async def _delete_factor(
204206
) -> AuthMFAAdminDeleteFactorResponse:
205207
validate_uuid(params.get("user_id"))
206208
validate_uuid(params.get("id"))
209+
response = await self._request(
207210
"DELETE",
208211
f"admin/users/{params.get('user_id')}/factors/{params.get('id')}",
209212
)
@@ -220,13 +223,10 @@ async def _list_oauth_clients(
220223
This function should only be called on a server.
221224
Never expose your `service_role` key in the browser.
222225
"""
223-
query = {}
224226
if params:
225-
if params.page is not None:
226-
query["page"] = str(params.page)
227-
if params.per_page is not None:
228-
query["per_page"] = str(params.per_page)
229-
227+
query = QueryParams(page=params.page, per_page=params.per_page)
228+
else:
229+
query = None
230230
response = await self._request(
231231
"GET",
232232
"admin/oauth/clients",
@@ -274,15 +274,15 @@ async def _create_oauth_client(
274274
This function should only be called on a server.
275275
Never expose your `service_role` key in the browser.
276276
"""
277-
return await self._request(
277+
response = await self._request(
278278
"POST",
279279
"admin/oauth/clients",
280280
body=params,
281-
xform=lambda data: OAuthClientResponse(
282-
client=model_validate(OAuthClient, data)
283-
),
284281
)
285282

283+
return OAuthClientResponse(
284+
client=model_validate(OAuthClient, response.content)
285+
)
286286
async def _get_oauth_client(
287287
self,
288288
client_id: str,
@@ -295,14 +295,13 @@ async def _get_oauth_client(
295295
Never expose your `service_role` key in the browser.
296296
"""
297297
validate_uuid(client_id)
298-
return await self._request(
298+
response = await self._request(
299299
"GET",
300300
f"admin/oauth/clients/{client_id}",
301-
xform=lambda data: OAuthClientResponse(
302-
client=model_validate(OAuthClient, data)
303-
),
304301
)
305-
302+
return OAuthClientResponse(
303+
client=model_validate(OAuthClient, response.content)
304+
)
306305
async def _delete_oauth_client(
307306
self,
308307
client_id: str,
@@ -315,12 +314,12 @@ async def _delete_oauth_client(
315314
Never expose your `service_role` key in the browser.
316315
"""
317316
validate_uuid(client_id)
318-
return await self._request(
317+
response = await self._request(
319318
"DELETE",
320319
f"admin/oauth/clients/{client_id}",
321-
xform=lambda data: OAuthClientResponse(
322-
client=model_validate(OAuthClient, data) if data else None
323-
),
320+
)
321+
return OAuthClientResponse(
322+
client=model_validate(OAuthClient, response.content) if response.content else None
324323
)
325324

326325
async def _regenerate_oauth_client_secret(
@@ -335,10 +334,10 @@ async def _regenerate_oauth_client_secret(
335334
Never expose your `service_role` key in the browser.
336335
"""
337336
validate_uuid(client_id)
338-
return await self._request(
337+
response = await self._request(
339338
"POST",
340339
f"admin/oauth/clients/{client_id}/regenerate_secret",
341-
xform=lambda data: OAuthClientResponse(
342-
client=model_validate(OAuthClient, data)
343-
),
340+
)
341+
return OAuthClientResponse(
342+
client=model_validate(OAuthClient, response.content)
344343
)

src/auth/src/supabase_auth/_async/gotrue_admin_oauth_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
OAuthClientResponse,
55
PageParams,
66
)
7+
from typing import Optional
78

89

910
class AsyncGoTrueAdminOAuthAPI:
@@ -14,7 +15,7 @@ class AsyncGoTrueAdminOAuthAPI:
1415

1516
async def list_clients(
1617
self,
17-
params: PageParams | None = None,
18+
params: Optional[PageParams] = None,
1819
) -> OAuthClientListResponse:
1920
"""
2021
Lists all OAuth clients with optional pagination.

src/auth/src/supabase_auth/_sync/gotrue_admin_api.py

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
from pydantic import TypeAdapter
77

88
from ..helpers import (
9-
is_valid_uuid,
9+
validate_uuid,
1010
model_validate,
1111
parse_link_response,
1212
parse_user_response,
13-
validate_uuid,
1413
)
1514
from ..http_clients import SyncClient
1615
from ..types import (
@@ -152,7 +151,7 @@ def get_user_by_id(self, uid: str) -> UserResponse:
152151
This function should only be called on a server.
153152
Never expose your `service_role` key in the browser.
154153
"""
155-
self._validate_uuid(uid)
154+
validate_uuid(uid)
156155

157156
response = self._request(
158157
"GET",
@@ -171,7 +170,7 @@ def update_user_by_id(
171170
This function should only be called on a server.
172171
Never expose your `service_role` key in the browser.
173172
"""
174-
self._validate_uuid(uid)
173+
validate_uuid(uid)
175174
response = self._request(
176175
"PUT",
177176
f"admin/users/{uid}",
@@ -186,15 +185,15 @@ def delete_user(self, id: str, should_soft_delete: bool = False) -> None:
186185
This function should only be called on a server.
187186
Never expose your `service_role` key in the browser.
188187
"""
189-
self._validate_uuid(id)
188+
validate_uuid(id)
190189
body = {"should_soft_delete": should_soft_delete}
191190
self._request("DELETE", f"admin/users/{id}", body=body)
192191

193192
def _list_factors(
194193
self,
195194
params: AuthMFAAdminListFactorsParams,
196195
) -> AuthMFAAdminListFactorsResponse:
197-
self._validate_uuid(params.get("user_id"))
196+
validate_uuid(params.get("user_id"))
198197
response = self._request(
199198
"GET",
200199
f"admin/users/{params.get('user_id')}/factors",
@@ -205,20 +204,14 @@ def _delete_factor(
205204
self,
206205
params: AuthMFAAdminDeleteFactorParams,
207206
) -> AuthMFAAdminDeleteFactorResponse:
208-
self._validate_uuid(params.get("user_id"))
209-
self._validate_uuid(params.get("id"))
207+
validate_uuid(params.get("user_id"))
208+
validate_uuid(params.get("id"))
210209
response = self._request(
211210
"DELETE",
212211
f"admin/users/{params.get('user_id')}/factors/{params.get('id')}",
213212
)
214213
return model_validate(AuthMFAAdminDeleteFactorResponse, response.content)
215214

216-
def _validate_uuid(self, id: str | None) -> None:
217-
if id is None:
218-
raise ValueError("Invalid id, id cannot be none")
219-
if not is_valid_uuid(id):
220-
raise ValueError(f"Invalid id, '{id}' is not a valid uuid")
221-
222215
def _list_oauth_clients(
223216
self,
224217
params: PageParams | None = None,
@@ -230,13 +223,10 @@ def _list_oauth_clients(
230223
This function should only be called on a server.
231224
Never expose your `service_role` key in the browser.
232225
"""
233-
query = {}
234226
if params:
235-
if params.page is not None:
236-
query["page"] = str(params.page)
237-
if params.per_page is not None:
238-
query["per_page"] = str(params.per_page)
239-
227+
query = QueryParams(page=params.page, per_page=params.per_page)
228+
else:
229+
query = None
240230
response = self._request(
241231
"GET",
242232
"admin/oauth/clients",
@@ -284,15 +274,15 @@ def _create_oauth_client(
284274
This function should only be called on a server.
285275
Never expose your `service_role` key in the browser.
286276
"""
287-
return self._request(
277+
response = self._request(
288278
"POST",
289279
"admin/oauth/clients",
290280
body=params,
291-
xform=lambda data: OAuthClientResponse(
292-
client=model_validate(OAuthClient, data)
293-
),
294281
)
295282

283+
return OAuthClientResponse(
284+
client=model_validate(OAuthClient, response.content)
285+
)
296286
def _get_oauth_client(
297287
self,
298288
client_id: str,
@@ -305,14 +295,13 @@ def _get_oauth_client(
305295
Never expose your `service_role` key in the browser.
306296
"""
307297
validate_uuid(client_id)
308-
return self._request(
298+
response = self._request(
309299
"GET",
310300
f"admin/oauth/clients/{client_id}",
311-
xform=lambda data: OAuthClientResponse(
312-
client=model_validate(OAuthClient, data)
313-
),
314301
)
315-
302+
return OAuthClientResponse(
303+
client=model_validate(OAuthClient, response.content)
304+
)
316305
def _delete_oauth_client(
317306
self,
318307
client_id: str,
@@ -325,12 +314,12 @@ def _delete_oauth_client(
325314
Never expose your `service_role` key in the browser.
326315
"""
327316
validate_uuid(client_id)
328-
return self._request(
317+
response = self._request(
329318
"DELETE",
330319
f"admin/oauth/clients/{client_id}",
331-
xform=lambda data: OAuthClientResponse(
332-
client=model_validate(OAuthClient, data) if data else None
333-
),
320+
)
321+
return OAuthClientResponse(
322+
client=model_validate(OAuthClient, response.content) if response.content else None
334323
)
335324

336325
def _regenerate_oauth_client_secret(
@@ -345,10 +334,10 @@ def _regenerate_oauth_client_secret(
345334
Never expose your `service_role` key in the browser.
346335
"""
347336
validate_uuid(client_id)
348-
return self._request(
337+
response = self._request(
349338
"POST",
350339
f"admin/oauth/clients/{client_id}/regenerate_secret",
351-
xform=lambda data: OAuthClientResponse(
352-
client=model_validate(OAuthClient, data)
353-
),
340+
)
341+
return OAuthClientResponse(
342+
client=model_validate(OAuthClient, response.content)
354343
)

src/auth/src/supabase_auth/_sync/gotrue_admin_oauth_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
OAuthClientResponse,
55
PageParams,
66
)
7+
from typing import Optional
78

89

910
class SyncGoTrueAdminOAuthAPI:
@@ -14,7 +15,7 @@ class SyncGoTrueAdminOAuthAPI:
1415

1516
def list_clients(
1617
self,
17-
params: PageParams | None = None,
18+
params: Optional[PageParams] = None,
1819
) -> OAuthClientListResponse:
1920
"""
2021
Lists all OAuth clients with optional pagination.

src/auth/src/supabase_auth/_sync/gotrue_client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ def sign_in_with_oauth(
441441
)
442442
return OAuthResponse(provider=provider, url=url_with_qs)
443443

444-
def link_identity(self, credentials: SignInWithOAuthCredentials) -> OAuthResponse:
444+
def link_identity(
445+
self, credentials: SignInWithOAuthCredentials
446+
) -> OAuthResponse:
445447
provider = credentials["provider"]
446448
options = credentials.get("options", {})
447449
redirect_to = options.get("redirect_to")
@@ -741,7 +743,9 @@ def set_session(self, access_token: str, refresh_token: str) -> AuthResponse:
741743
self._notify_all_subscribers("TOKEN_REFRESHED", session)
742744
return AuthResponse(session=session, user=session.user)
743745

744-
def refresh_session(self, refresh_token: Optional[str] = None) -> AuthResponse:
746+
def refresh_session(
747+
self, refresh_token: Optional[str] = None
748+
) -> AuthResponse:
745749
"""
746750
Returns a new session, regardless of expiry status.
747751
@@ -1149,7 +1153,9 @@ def _get_url_for_provider(
11491153
if self._flow_type == "pkce":
11501154
code_verifier = generate_pkce_verifier()
11511155
code_challenge = generate_pkce_challenge(code_verifier)
1152-
self._storage.set_item(f"{self._storage_key}-code-verifier", code_verifier)
1156+
self._storage.set_item(
1157+
f"{self._storage_key}-code-verifier", code_verifier
1158+
)
11531159
code_challenge_method = (
11541160
"plain" if code_verifier == code_challenge else "s256"
11551161
)

src/auth/src/supabase_auth/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ def is_valid_uuid(value: str) -> bool:
299299
except ValueError:
300300
return False
301301

302-
def validate_uuid(id: str) -> None:
302+
def validate_uuid(id: str | None) -> None:
303+
if id is None:
304+
raise ValueError("Invalid id, id is None")
303305
if not is_valid_uuid(id):
304306
raise ValueError(f"Invalid id, '{id}' is not a valid uuid")

0 commit comments

Comments
 (0)