supabase_auth 2.22.4__tar.gz → 2.23.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/PKG-INFO +1 -1
  2. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/pyproject.toml +4 -4
  3. supabase_auth-2.23.0/src/supabase_auth/__init__.py +16 -0
  4. supabase_auth-2.23.0/src/supabase_auth/_async/gotrue_admin_api.py +353 -0
  5. supabase_auth-2.23.0/src/supabase_auth/_async/gotrue_admin_oauth_api.py +95 -0
  6. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_async/gotrue_base_api.py +3 -3
  7. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_async/gotrue_client.py +31 -24
  8. supabase_auth-2.23.0/src/supabase_auth/_sync/gotrue_admin_api.py +353 -0
  9. supabase_auth-2.23.0/src/supabase_auth/_sync/gotrue_admin_oauth_api.py +95 -0
  10. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_sync/gotrue_base_api.py +3 -3
  11. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_sync/gotrue_client.py +27 -24
  12. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/errors.py +1 -1
  13. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/helpers.py +20 -13
  14. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/timer.py +2 -2
  15. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/types.py +156 -0
  16. supabase_auth-2.23.0/src/supabase_auth/version.py +1 -0
  17. supabase_auth-2.22.4/src/supabase_auth/__init__.py +0 -16
  18. supabase_auth-2.22.4/src/supabase_auth/_async/gotrue_admin_api.py +0 -207
  19. supabase_auth-2.22.4/src/supabase_auth/_sync/gotrue_admin_api.py +0 -207
  20. supabase_auth-2.22.4/src/supabase_auth/version.py +0 -1
  21. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/README.md +0 -0
  22. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_async/__init__.py +0 -0
  23. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_async/gotrue_admin_mfa_api.py +0 -0
  24. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_async/gotrue_mfa_api.py +0 -0
  25. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_async/storage.py +0 -0
  26. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_sync/__init__.py +0 -0
  27. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_sync/gotrue_admin_mfa_api.py +0 -0
  28. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_sync/gotrue_mfa_api.py +0 -0
  29. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/_sync/storage.py +0 -0
  30. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/constants.py +0 -0
  31. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/http_clients.py +0 -0
  32. {supabase_auth-2.22.4 → supabase_auth-2.23.0}/src/supabase_auth/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: supabase-auth
3
- Version: 2.22.4
3
+ Version: 2.23.0
4
4
  Summary: Python Client Library for Supabase Auth
5
5
  Author: Joel Lee
6
6
  Author-email: Joel Lee <joel@joellee.org>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "supabase_auth"
3
- version = "2.22.4" # {x-release-please-version}
3
+ version = "2.23.0" # {x-release-please-version}
4
4
  description = "Python Client Library for Supabase Auth"
5
5
  authors = [
6
6
  {name = "Joel Lee", email = "joel@joellee.org" }
@@ -59,14 +59,14 @@ select = [
59
59
  # pyupgrade
60
60
  "UP",
61
61
  # flake8-bugbear
62
- # "B",
62
+ "B",
63
63
  # flake8-simplify
64
64
  # "SIM",
65
65
  # isort
66
66
  "I",
67
+ "ANN2"
67
68
  ]
68
- ignore = ["F401", "F403", "F841", "E712", "E501", "E402", "E722", "E731", "UP006", "UP035"]
69
- # isort.required-imports = ["from __future__ import annotations"]
69
+ ignore = ["F403", "E501", "E402", "UP006", "UP035"]
70
70
 
71
71
  [tool.ruff.lint.pyupgrade]
72
72
  # Preserve types, even if a file imports `from __future__ import annotations`.
@@ -0,0 +1,16 @@
1
+ from __future__ import annotations
2
+
3
+ from ._async.gotrue_admin_api import AsyncGoTrueAdminAPI # noqa
4
+ from ._async.gotrue_client import AsyncGoTrueClient # noqa
5
+ from ._async.storage import (
6
+ AsyncMemoryStorage, # noqa
7
+ AsyncSupportedStorage, # noqa
8
+ )
9
+ from ._sync.gotrue_admin_api import SyncGoTrueAdminAPI # noqa
10
+ from ._sync.gotrue_client import SyncGoTrueClient # noqa
11
+ from ._sync.storage import (
12
+ SyncMemoryStorage, # noqa
13
+ SyncSupportedStorage, # noqa
14
+ )
15
+ from .types import *
16
+ from .version import __version__ # noqa
@@ -0,0 +1,353 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Dict, List, Optional
4
+
5
+ from httpx import QueryParams
6
+
7
+ from ..helpers import (
8
+ model_validate,
9
+ parse_link_response,
10
+ parse_user_response,
11
+ validate_uuid,
12
+ )
13
+ from ..http_clients import AsyncClient
14
+ from ..types import (
15
+ AdminUserAttributes,
16
+ AuthMFAAdminDeleteFactorParams,
17
+ AuthMFAAdminDeleteFactorResponse,
18
+ AuthMFAAdminListFactorsParams,
19
+ AuthMFAAdminListFactorsResponse,
20
+ CreateOAuthClientParams,
21
+ GenerateLinkParams,
22
+ GenerateLinkResponse,
23
+ InviteUserByEmailOptions,
24
+ OAuthClient,
25
+ OAuthClientListResponse,
26
+ OAuthClientResponse,
27
+ PageParams,
28
+ SignOutScope,
29
+ UpdateOAuthClientParams,
30
+ User,
31
+ UserList,
32
+ UserResponse,
33
+ )
34
+ from .gotrue_admin_mfa_api import AsyncGoTrueAdminMFAAPI
35
+ from .gotrue_admin_oauth_api import AsyncGoTrueAdminOAuthAPI
36
+ from .gotrue_base_api import AsyncGoTrueBaseAPI
37
+
38
+
39
+ class AsyncGoTrueAdminAPI(AsyncGoTrueBaseAPI):
40
+ def __init__(
41
+ self,
42
+ *,
43
+ url: str = "",
44
+ headers: Optional[Dict[str, str]] = None,
45
+ http_client: Optional[AsyncClient] = None,
46
+ verify: bool = True,
47
+ proxy: Optional[str] = None,
48
+ ) -> None:
49
+ http_headers = headers or {}
50
+ AsyncGoTrueBaseAPI.__init__(
51
+ self,
52
+ url=url,
53
+ headers=http_headers,
54
+ http_client=http_client,
55
+ verify=verify,
56
+ proxy=proxy,
57
+ )
58
+ # TODO(@o-santi): why is is this done this way?
59
+ self.mfa = AsyncGoTrueAdminMFAAPI()
60
+ self.mfa.list_factors = self._list_factors # type: ignore
61
+ self.mfa.delete_factor = self._delete_factor # type: ignore
62
+ self.oauth = AsyncGoTrueAdminOAuthAPI()
63
+ self.oauth.list_clients = self._list_oauth_clients # type: ignore
64
+ self.oauth.create_client = self._create_oauth_client # type: ignore
65
+ self.oauth.get_client = self._get_oauth_client # type: ignore
66
+ self.oauth.update_client = self._update_oauth_client # type: ignore
67
+ self.oauth.delete_client = self._delete_oauth_client # type: ignore
68
+ self.oauth.regenerate_client_secret = self._regenerate_oauth_client_secret # type: ignore
69
+
70
+ async def sign_out(self, jwt: str, scope: SignOutScope = "global") -> None:
71
+ """
72
+ Removes a logged-in session.
73
+ """
74
+ await self._request(
75
+ "POST",
76
+ "logout",
77
+ query=QueryParams(scope=scope),
78
+ jwt=jwt,
79
+ no_resolve_json=True,
80
+ )
81
+
82
+ async def invite_user_by_email(
83
+ self,
84
+ email: str,
85
+ options: Optional[InviteUserByEmailOptions] = None,
86
+ ) -> UserResponse:
87
+ """
88
+ Sends an invite link to an email address.
89
+ """
90
+ email_options = options or {}
91
+ response = await self._request(
92
+ "POST",
93
+ "invite",
94
+ body={"email": email, "data": email_options.get("data")},
95
+ redirect_to=email_options.get("redirect_to"),
96
+ )
97
+ return parse_user_response(response)
98
+
99
+ async def generate_link(self, params: GenerateLinkParams) -> GenerateLinkResponse:
100
+ """
101
+ Generates email links and OTPs to be sent via a custom email provider.
102
+ """
103
+ response = await self._request(
104
+ "POST",
105
+ "admin/generate_link",
106
+ body={
107
+ "type": params.get("type"),
108
+ "email": params.get("email"),
109
+ "password": params.get("password"),
110
+ "new_email": params.get("new_email"),
111
+ "data": params.get("options", {}).get("data"),
112
+ },
113
+ redirect_to=params.get("options", {}).get("redirect_to"),
114
+ )
115
+
116
+ return parse_link_response(response)
117
+
118
+ # User Admin API
119
+
120
+ async def create_user(self, attributes: AdminUserAttributes) -> UserResponse:
121
+ """
122
+ Creates a new user.
123
+
124
+ This function should only be called on a server.
125
+ Never expose your `service_role` key in the browser.
126
+ """
127
+ response = await self._request(
128
+ "POST",
129
+ "admin/users",
130
+ body=attributes,
131
+ )
132
+ return parse_user_response(response)
133
+
134
+ async def list_users(
135
+ self, page: Optional[int] = None, per_page: Optional[int] = None
136
+ ) -> List[User]:
137
+ """
138
+ Get a list of users.
139
+
140
+ This function should only be called on a server.
141
+ Never expose your `service_role` key in the browser.
142
+ """
143
+ response = await self._request(
144
+ "GET",
145
+ "admin/users",
146
+ query=QueryParams(page=page, per_page=per_page),
147
+ )
148
+ return model_validate(UserList, response.content).users
149
+
150
+ async def get_user_by_id(self, uid: str) -> UserResponse:
151
+ """
152
+ Get user by id.
153
+
154
+ This function should only be called on a server.
155
+ Never expose your `service_role` key in the browser.
156
+ """
157
+ validate_uuid(uid)
158
+
159
+ response = await self._request(
160
+ "GET",
161
+ f"admin/users/{uid}",
162
+ )
163
+ return parse_user_response(response)
164
+
165
+ async def update_user_by_id(
166
+ self,
167
+ uid: str,
168
+ attributes: AdminUserAttributes,
169
+ ) -> UserResponse:
170
+ """
171
+ Updates the user data.
172
+
173
+ This function should only be called on a server.
174
+ Never expose your `service_role` key in the browser.
175
+ """
176
+ validate_uuid(uid)
177
+ response = await self._request(
178
+ "PUT",
179
+ f"admin/users/{uid}",
180
+ body=attributes,
181
+ )
182
+ return parse_user_response(response)
183
+
184
+ async def delete_user(self, id: str, should_soft_delete: bool = False) -> None:
185
+ """
186
+ Delete a user. Requires a `service_role` key.
187
+
188
+ This function should only be called on a server.
189
+ Never expose your `service_role` key in the browser.
190
+ """
191
+ validate_uuid(id)
192
+ body = {"should_soft_delete": should_soft_delete}
193
+ await self._request("DELETE", f"admin/users/{id}", body=body)
194
+
195
+ async def _list_factors(
196
+ self,
197
+ params: AuthMFAAdminListFactorsParams,
198
+ ) -> AuthMFAAdminListFactorsResponse:
199
+ validate_uuid(params.get("user_id"))
200
+ response = await self._request(
201
+ "GET",
202
+ f"admin/users/{params.get('user_id')}/factors",
203
+ )
204
+ return model_validate(AuthMFAAdminListFactorsResponse, response.content)
205
+
206
+ async def _delete_factor(
207
+ self,
208
+ params: AuthMFAAdminDeleteFactorParams,
209
+ ) -> AuthMFAAdminDeleteFactorResponse:
210
+ validate_uuid(params.get("user_id"))
211
+ validate_uuid(params.get("id"))
212
+ response = await self._request(
213
+ "DELETE",
214
+ f"admin/users/{params.get('user_id')}/factors/{params.get('id')}",
215
+ )
216
+ return model_validate(AuthMFAAdminDeleteFactorResponse, response.content)
217
+
218
+ async def _list_oauth_clients(
219
+ self,
220
+ params: PageParams | None = None,
221
+ ) -> OAuthClientListResponse:
222
+ """
223
+ Lists all OAuth clients with optional pagination.
224
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
225
+
226
+ This function should only be called on a server.
227
+ Never expose your `service_role` key in the browser.
228
+ """
229
+ if params:
230
+ query = QueryParams(page=params.page, per_page=params.per_page)
231
+ else:
232
+ query = None
233
+ response = await self._request(
234
+ "GET",
235
+ "admin/oauth/clients",
236
+ query=query,
237
+ no_resolve_json=True,
238
+ )
239
+
240
+ result = model_validate(OAuthClientListResponse, response.content)
241
+
242
+ # Parse pagination headers
243
+ total = response.headers.get("x-total-count")
244
+ if total:
245
+ result.total = int(total)
246
+
247
+ links = response.headers.get("link")
248
+ if links:
249
+ for link in links.split(","):
250
+ parts = link.split(";")
251
+ if len(parts) >= 2:
252
+ page_match = parts[0].split("page=")
253
+ if len(page_match) >= 2:
254
+ page_num = int(page_match[1].split("&")[0].rstrip(">"))
255
+ rel = parts[1].split("=")[1].strip('"')
256
+ if rel == "next":
257
+ result.next_page = page_num
258
+ elif rel == "last":
259
+ result.last_page = page_num
260
+
261
+ return result
262
+
263
+ async def _create_oauth_client(
264
+ self,
265
+ params: CreateOAuthClientParams,
266
+ ) -> OAuthClientResponse:
267
+ """
268
+ Creates a new OAuth client.
269
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
270
+
271
+ This function should only be called on a server.
272
+ Never expose your `service_role` key in the browser.
273
+ """
274
+ response = await self._request(
275
+ "POST",
276
+ "admin/oauth/clients",
277
+ body=params,
278
+ )
279
+
280
+ return OAuthClientResponse(client=model_validate(OAuthClient, response.content))
281
+
282
+ async def _get_oauth_client(
283
+ self,
284
+ client_id: str,
285
+ ) -> OAuthClientResponse:
286
+ """
287
+ Gets details of a specific OAuth client.
288
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
289
+
290
+ This function should only be called on a server.
291
+ Never expose your `service_role` key in the browser.
292
+ """
293
+ validate_uuid(client_id)
294
+ response = await self._request(
295
+ "GET",
296
+ f"admin/oauth/clients/{client_id}",
297
+ )
298
+ return OAuthClientResponse(client=model_validate(OAuthClient, response.content))
299
+
300
+ async def _update_oauth_client(
301
+ self,
302
+ client_id: str,
303
+ params: UpdateOAuthClientParams,
304
+ ) -> OAuthClientResponse:
305
+ """
306
+ Updates an OAuth client.
307
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
308
+
309
+ This function should only be called on a server.
310
+ Never expose your `service_role` key in the browser.
311
+ """
312
+ validate_uuid(client_id)
313
+ response = await self._request(
314
+ "PUT",
315
+ f"admin/oauth/clients/{client_id}",
316
+ body=params,
317
+ )
318
+ return OAuthClientResponse(client=model_validate(OAuthClient, response.content))
319
+
320
+ async def _delete_oauth_client(
321
+ self,
322
+ client_id: str,
323
+ ) -> None:
324
+ """
325
+ Deletes an OAuth client.
326
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
327
+
328
+ This function should only be called on a server.
329
+ Never expose your `service_role` key in the browser.
330
+ """
331
+ validate_uuid(client_id)
332
+ await self._request(
333
+ "DELETE",
334
+ f"admin/oauth/clients/{client_id}",
335
+ )
336
+
337
+ async def _regenerate_oauth_client_secret(
338
+ self,
339
+ client_id: str,
340
+ ) -> OAuthClientResponse:
341
+ """
342
+ Regenerates the secret for an OAuth client.
343
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
344
+
345
+ This function should only be called on a server.
346
+ Never expose your `service_role` key in the browser.
347
+ """
348
+ validate_uuid(client_id)
349
+ response = await self._request(
350
+ "POST",
351
+ f"admin/oauth/clients/{client_id}/regenerate_secret",
352
+ )
353
+ return OAuthClientResponse(client=model_validate(OAuthClient, response.content))
@@ -0,0 +1,95 @@
1
+ from typing import Optional
2
+
3
+ from ..types import (
4
+ CreateOAuthClientParams,
5
+ OAuthClientListResponse,
6
+ OAuthClientResponse,
7
+ PageParams,
8
+ UpdateOAuthClientParams,
9
+ )
10
+
11
+
12
+ class AsyncGoTrueAdminOAuthAPI:
13
+ """
14
+ Contains all OAuth client administration methods.
15
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
16
+ """
17
+
18
+ async def list_clients(
19
+ self,
20
+ params: Optional[PageParams] = None,
21
+ ) -> OAuthClientListResponse:
22
+ """
23
+ Lists all OAuth clients with optional pagination.
24
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
25
+
26
+ This function should only be called on a server.
27
+ Never expose your `service_role` key in the browser.
28
+ """
29
+ raise NotImplementedError() # pragma: no cover
30
+
31
+ async def create_client(
32
+ self,
33
+ params: CreateOAuthClientParams,
34
+ ) -> OAuthClientResponse:
35
+ """
36
+ Creates a new OAuth client.
37
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
38
+
39
+ This function should only be called on a server.
40
+ Never expose your `service_role` key in the browser.
41
+ """
42
+ raise NotImplementedError() # pragma: no cover
43
+
44
+ async def get_client(
45
+ self,
46
+ client_id: str,
47
+ ) -> OAuthClientResponse:
48
+ """
49
+ Gets details of a specific OAuth client.
50
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
51
+
52
+ This function should only be called on a server.
53
+ Never expose your `service_role` key in the browser.
54
+ """
55
+ raise NotImplementedError() # pragma: no cover
56
+
57
+ async def update_client(
58
+ self,
59
+ client_id: str,
60
+ params: UpdateOAuthClientParams,
61
+ ) -> OAuthClientResponse:
62
+ """
63
+ Updates an OAuth client.
64
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
65
+
66
+ This function should only be called on a server.
67
+ Never expose your `service_role` key in the browser.
68
+ """
69
+ raise NotImplementedError() # pragma: no cover
70
+
71
+ async def delete_client(
72
+ self,
73
+ client_id: str,
74
+ ) -> OAuthClientResponse:
75
+ """
76
+ Deletes an OAuth client.
77
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
78
+
79
+ This function should only be called on a server.
80
+ Never expose your `service_role` key in the browser.
81
+ """
82
+ raise NotImplementedError() # pragma: no cover
83
+
84
+ async def regenerate_client_secret(
85
+ self,
86
+ client_id: str,
87
+ ) -> OAuthClientResponse:
88
+ """
89
+ Regenerates the secret for an OAuth client.
90
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
91
+
92
+ This function should only be called on a server.
93
+ Never expose your `service_role` key in the browser.
94
+ """
95
+ raise NotImplementedError() # pragma: no cover
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import Any, Callable, Dict, Optional, TypeVar, overload
3
+ from typing import Any, Dict, Optional
4
4
 
5
5
  from httpx import HTTPStatusError, QueryParams, Response
6
6
  from pydantic import BaseModel
@@ -20,7 +20,7 @@ class AsyncGoTrueBaseAPI:
20
20
  http_client: Optional[AsyncClient],
21
21
  verify: bool = True,
22
22
  proxy: Optional[str] = None,
23
- ):
23
+ ) -> None:
24
24
  self._url = url
25
25
  self._headers = headers
26
26
  self._http_client = http_client or AsyncClient(
@@ -74,4 +74,4 @@ class AsyncGoTrueBaseAPI:
74
74
  response.raise_for_status()
75
75
  return response
76
76
  except (HTTPStatusError, RuntimeError) as e:
77
- raise handle_exception(e)
77
+ raise handle_exception(e) # noqa