supabase_auth 0.1.0__tar.gz → 2.4.3__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 (27) hide show
  1. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/PKG-INFO +15 -14
  2. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/README.md +8 -8
  3. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/pyproject.toml +13 -13
  4. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/__init__.py +1 -1
  5. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_async/gotrue_admin_api.py +7 -3
  6. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_async/gotrue_base_api.py +5 -7
  7. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_async/gotrue_client.py +95 -3
  8. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_async/storage.py +3 -6
  9. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_sync/api.py +10 -9
  10. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_sync/client.py +4 -0
  11. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_sync/gotrue_admin_api.py +7 -3
  12. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_sync/gotrue_base_api.py +5 -7
  13. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_sync/gotrue_client.py +95 -3
  14. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_sync/storage.py +3 -6
  15. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/helpers.py +15 -5
  16. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/types.py +25 -0
  17. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/LICENSE +0 -0
  18. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_async/__init__.py +0 -0
  19. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_async/gotrue_admin_mfa_api.py +0 -0
  20. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_async/gotrue_mfa_api.py +0 -0
  21. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_sync/__init__.py +0 -0
  22. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_sync/gotrue_admin_mfa_api.py +0 -0
  23. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/_sync/gotrue_mfa_api.py +0 -0
  24. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/constants.py +0 -0
  25. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/errors.py +0 -0
  26. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/http_clients.py +0 -0
  27. {supabase_auth-0.1.0 → supabase_auth-2.4.3}/supabase_auth/timer.py +0 -0
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supabase_auth
3
- Version: 0.1.0
4
- Summary: Python Client Library for GoTrue
5
- Home-page: https://github.com/supabase-community/gotrue-py
3
+ Version: 2.4.3
4
+ Summary: Python Client Library for Supabase Auth
5
+ Home-page: https://github.com/supabase-community/auth-py
6
6
  License: MIT
7
7
  Author: Joel Lee
8
8
  Author-email: joel@joellee.org
@@ -14,13 +14,14 @@ Classifier: Programming Language :: Python :: 3.8
14
14
  Classifier: Programming Language :: Python :: 3.9
15
15
  Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
- Requires-Dist: httpx (>=0.23,<0.26)
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Requires-Dist: httpx (>=0.23,<0.28)
18
19
  Requires-Dist: pydantic (>=1.10,<3)
19
- Project-URL: Documentation, https://github.com/supabase-community/gotrue-py
20
- Project-URL: Repository, https://github.com/supabase-community/gotrue-py
20
+ Project-URL: Documentation, https://github.com/supabase-community/auth-py
21
+ Project-URL: Repository, https://github.com/supabase-community/auth-py
21
22
  Description-Content-Type: text/markdown
22
23
 
23
- # gotrue-py
24
+ # Auth-py
24
25
 
25
26
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?label=license)](https://opensource.org/licenses/MIT)
26
27
  [![CI](https://github.com/supabase-community/gotrue-py/actions/workflows/ci.yml/badge.svg)](https://github.com/supabase-community/gotrue-py/actions/workflows/ci.yml)
@@ -34,22 +35,22 @@ Description-Content-Type: text/markdown
34
35
  [![Github Watchers](https://img.shields.io/github/watchers/supabase-community/gotrue-py?style=flat&logo=github)](https://github.com/supabase-community/gotrue-py)
35
36
  [![GitHub contributors](https://img.shields.io/github/contributors/supabase-community/gotrue-py)](https://github.com/supabase-community/gotrue-py/graphs/contributors)
36
37
 
37
- This is a Python port of the [supabase js gotrue client](https://github.com/supabase/gotrue-js). The current state is that there is a features parity but with small differences that are mentioned in the section **Differences to the JS client**.
38
+ This is a Python port of the [supabase js gotrue client](https://github.com/supabase/gotrue-js). The current state is that there is a features parity but with small differences that are mentioned in the section **Differences to the JS client**. As of December 14th, we renamed to repo from `gotrue-py` to `auth-py` to mirror the changes in the JavaScript library.
38
39
 
39
40
  ## Installation
40
41
 
41
- We are still working on making the `gotrue` python library more user-friendly. For now here are some sparse notes on how to install the module.
42
+ We are still working on making the `supabase_auth` python library more user-friendly. For now here are some sparse notes on how to install the module.
42
43
 
43
44
  ### Poetry
44
45
 
45
46
  ```bash
46
- poetry add gotrue
47
+ poetry add supabase_auth
47
48
  ```
48
49
 
49
50
  ### Pip
50
51
 
51
52
  ```bash
52
- pip install gotrue
53
+ pip install supabase_auth
53
54
  ```
54
55
 
55
56
  ## Differences to the JS client
@@ -68,7 +69,7 @@ const { data, error } = client.sign_up(...)
68
69
 
69
70
  The other key difference is we do not use pascalCase to encode variable and method names. Instead we use the snake_case convention adopted in the Python language.
70
71
 
71
- Also, the `gotrue` library for Python parses the date-time string into `datetime` Python objects. The [JS client](https://github.com/supabase/gotrue-js) keeps the date-time as strings.
72
+ Also, the `supabase_auth` library for Python parses the date-time string into `datetime` Python objects. The [JS client](https://github.com/supabase/gotrue-js) keeps the date-time as strings.
72
73
 
73
74
  ## Usage (outdated)
74
75
 
@@ -77,7 +78,7 @@ Also, the `gotrue` library for Python parses the date-time string into `datetime
77
78
  To instantiate the client, you'll need the URL and any request headers at a minimum.
78
79
 
79
80
  ```python
80
- from gotrue import SyncGoTrueClient
81
+ from supabase_auth import SyncGoTrueClient
81
82
 
82
83
  headers = {
83
84
  "apiKey": "my-mega-awesome-api-key",
@@ -117,5 +118,5 @@ assert client.session() is not None
117
118
 
118
119
  ## Contributions
119
120
 
120
- We would be immensely grateful for any contributions to this project. In particular are the following items:
121
+ We would be immensely grateful for any contributions to this project.
121
122
 
@@ -1,4 +1,4 @@
1
- # gotrue-py
1
+ # Auth-py
2
2
 
3
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?label=license)](https://opensource.org/licenses/MIT)
4
4
  [![CI](https://github.com/supabase-community/gotrue-py/actions/workflows/ci.yml/badge.svg)](https://github.com/supabase-community/gotrue-py/actions/workflows/ci.yml)
@@ -12,22 +12,22 @@
12
12
  [![Github Watchers](https://img.shields.io/github/watchers/supabase-community/gotrue-py?style=flat&logo=github)](https://github.com/supabase-community/gotrue-py)
13
13
  [![GitHub contributors](https://img.shields.io/github/contributors/supabase-community/gotrue-py)](https://github.com/supabase-community/gotrue-py/graphs/contributors)
14
14
 
15
- This is a Python port of the [supabase js gotrue client](https://github.com/supabase/gotrue-js). The current state is that there is a features parity but with small differences that are mentioned in the section **Differences to the JS client**.
15
+ This is a Python port of the [supabase js gotrue client](https://github.com/supabase/gotrue-js). The current state is that there is a features parity but with small differences that are mentioned in the section **Differences to the JS client**. As of December 14th, we renamed to repo from `gotrue-py` to `auth-py` to mirror the changes in the JavaScript library.
16
16
 
17
17
  ## Installation
18
18
 
19
- We are still working on making the `gotrue` python library more user-friendly. For now here are some sparse notes on how to install the module.
19
+ We are still working on making the `supabase_auth` python library more user-friendly. For now here are some sparse notes on how to install the module.
20
20
 
21
21
  ### Poetry
22
22
 
23
23
  ```bash
24
- poetry add gotrue
24
+ poetry add supabase_auth
25
25
  ```
26
26
 
27
27
  ### Pip
28
28
 
29
29
  ```bash
30
- pip install gotrue
30
+ pip install supabase_auth
31
31
  ```
32
32
 
33
33
  ## Differences to the JS client
@@ -46,7 +46,7 @@ const { data, error } = client.sign_up(...)
46
46
 
47
47
  The other key difference is we do not use pascalCase to encode variable and method names. Instead we use the snake_case convention adopted in the Python language.
48
48
 
49
- Also, the `gotrue` library for Python parses the date-time string into `datetime` Python objects. The [JS client](https://github.com/supabase/gotrue-js) keeps the date-time as strings.
49
+ Also, the `supabase_auth` library for Python parses the date-time string into `datetime` Python objects. The [JS client](https://github.com/supabase/gotrue-js) keeps the date-time as strings.
50
50
 
51
51
  ## Usage (outdated)
52
52
 
@@ -55,7 +55,7 @@ Also, the `gotrue` library for Python parses the date-time string into `datetime
55
55
  To instantiate the client, you'll need the URL and any request headers at a minimum.
56
56
 
57
57
  ```python
58
- from gotrue import SyncGoTrueClient
58
+ from supabase_auth import SyncGoTrueClient
59
59
 
60
60
  headers = {
61
61
  "apiKey": "my-mega-awesome-api-key",
@@ -95,4 +95,4 @@ assert client.session() is not None
95
95
 
96
96
  ## Contributions
97
97
 
98
- We would be immensely grateful for any contributions to this project. In particular are the following items:
98
+ We would be immensely grateful for any contributions to this project.
@@ -1,11 +1,11 @@
1
1
  [tool.poetry]
2
2
  name = "supabase_auth"
3
- version = "0.1.0"
4
- description = "Python Client Library for GoTrue"
3
+ version = "2.4.3"
4
+ description = "Python Client Library for Supabase Auth"
5
5
  authors = ["Joel Lee <joel@joellee.org>"]
6
- homepage = "https://github.com/supabase-community/gotrue-py"
7
- repository = "https://github.com/supabase-community/gotrue-py"
8
- documentation = "https://github.com/supabase-community/gotrue-py"
6
+ homepage = "https://github.com/supabase-community/auth-py"
7
+ repository = "https://github.com/supabase-community/auth-py"
8
+ documentation = "https://github.com/supabase-community/auth-py"
9
9
  readme = "README.md"
10
10
  license = "MIT"
11
11
  classifiers = [
@@ -16,27 +16,27 @@ classifiers = [
16
16
 
17
17
  [tool.poetry.dependencies]
18
18
  python = "^3.8"
19
- httpx = ">=0.23,<0.26"
19
+ httpx = ">=0.23,<0.28"
20
20
  pydantic = ">=1.10,<3"
21
21
 
22
22
  [tool.poetry.dev-dependencies]
23
- pytest = "^7.4.2"
23
+ pytest = "^8.2.1"
24
24
  flake8 = "^5.0.4"
25
- black = "^23.9.1"
25
+ black = "^24.4.2"
26
26
  isort = "^5.12.0"
27
27
  pre-commit = "^3.4.0"
28
- pytest-cov = "^4.0.0"
28
+ pytest-cov = "^5.0.0"
29
29
  pytest-depends = "^1.0.1"
30
- pytest-asyncio = "^0.21.1"
31
- Faker = "^19.6.1"
30
+ pytest-asyncio = "^0.23.7"
31
+ Faker = "^25.2.0"
32
32
  unasync-cli = "^0.0.9"
33
- python-semantic-release = "^8.1.1"
33
+ python-semantic-release = "^9.8.0"
34
34
 
35
35
  [tool.poetry.group.dev.dependencies]
36
36
  pygithub = ">=1.57,<3.0"
37
37
 
38
38
  [tool.semantic_release]
39
- version_variables = ["gotrue/__init__.py:__version__"]
39
+ version_variables = ["supabase_auth/__init__.py:__version__"]
40
40
  version_toml = ["pyproject.toml:tool.poetry.version"]
41
41
  major_on_zero = false
42
42
  commit_message = "chore(release): bump version to v{version}"
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "2.1.0"
3
+ __version__ = "2.4.3"
4
4
 
5
5
  from ._async.gotrue_admin_api import AsyncGoTrueAdminAPI # type: ignore # noqa: F401
6
6
  from ._async.gotrue_client import AsyncGoTrueClient # type: ignore # noqa: F401
@@ -29,12 +29,14 @@ class AsyncGoTrueAdminAPI(AsyncGoTrueBaseAPI):
29
29
  url: str = "",
30
30
  headers: Dict[str, str] = {},
31
31
  http_client: Union[AsyncClient, None] = None,
32
+ verify: bool = True,
32
33
  ) -> None:
33
34
  AsyncGoTrueBaseAPI.__init__(
34
35
  self,
35
36
  url=url,
36
37
  headers=headers,
37
38
  http_client=http_client,
39
+ verify=verify,
38
40
  )
39
41
  self.mfa = AsyncGoTrueAdminMFAAPI()
40
42
  self.mfa.list_factors = self._list_factors
@@ -113,9 +115,11 @@ class AsyncGoTrueAdminAPI(AsyncGoTrueBaseAPI):
113
115
  "GET",
114
116
  "admin/users",
115
117
  query={"page": page, "per_page": per_page},
116
- xform=lambda data: [model_validate(User, user) for user in data["users"]]
117
- if "users" in data
118
- else [],
118
+ xform=lambda data: (
119
+ [model_validate(User, user) for user in data["users"]]
120
+ if "users" in data
121
+ else []
122
+ ),
119
123
  )
120
124
 
121
125
  async def get_user_by_id(self, uid: str) -> UserResponse:
@@ -19,10 +19,11 @@ class AsyncGoTrueBaseAPI:
19
19
  url: str,
20
20
  headers: Dict[str, str],
21
21
  http_client: Union[AsyncClient, None],
22
+ verify: bool = True,
22
23
  ):
23
24
  self._url = url
24
25
  self._headers = headers
25
- self._http_client = http_client or AsyncClient()
26
+ self._http_client = http_client or AsyncClient(verify=bool(verify))
26
27
 
27
28
  async def __aenter__(self) -> Self:
28
29
  return self
@@ -46,8 +47,7 @@ class AsyncGoTrueBaseAPI:
46
47
  body: Union[Any, None] = None,
47
48
  no_resolve_json: Literal[False] = False,
48
49
  xform: Callable[[Any], T],
49
- ) -> T:
50
- ... # pragma: no cover
50
+ ) -> T: ... # pragma: no cover
51
51
 
52
52
  @overload
53
53
  async def _request(
@@ -62,8 +62,7 @@ class AsyncGoTrueBaseAPI:
62
62
  body: Union[Any, None] = None,
63
63
  no_resolve_json: Literal[True],
64
64
  xform: Callable[[Response], T],
65
- ) -> T:
66
- ... # pragma: no cover
65
+ ) -> T: ... # pragma: no cover
67
66
 
68
67
  @overload
69
68
  async def _request(
@@ -77,8 +76,7 @@ class AsyncGoTrueBaseAPI:
77
76
  query: Union[Dict[str, str], None] = None,
78
77
  body: Union[Any, None] = None,
79
78
  no_resolve_json: bool = False,
80
- ) -> None:
81
- ... # pragma: no cover
79
+ ) -> None: ... # pragma: no cover
82
80
 
83
81
  async def _request(
84
82
  self,
@@ -30,7 +30,9 @@ from ..helpers import (
30
30
  model_dump,
31
31
  model_dump_json,
32
32
  model_validate,
33
+ parse_auth_otp_response,
33
34
  parse_auth_response,
35
+ parse_sso_response,
34
36
  parse_user_response,
35
37
  )
36
38
  from ..http_clients import AsyncClient
@@ -45,9 +47,11 @@ from ..types import (
45
47
  AuthMFAListFactorsResponse,
46
48
  AuthMFAUnenrollResponse,
47
49
  AuthMFAVerifyResponse,
50
+ AuthOtpResponse,
48
51
  AuthResponse,
49
52
  CodeExchangeParams,
50
53
  DecodedJWTDict,
54
+ IdentitiesResponse,
51
55
  MFAChallengeAndVerifyParams,
52
56
  MFAChallengeParams,
53
57
  MFAEnrollParams,
@@ -85,12 +89,14 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
85
89
  storage: Union[AsyncSupportedStorage, None] = None,
86
90
  http_client: Union[AsyncClient, None] = None,
87
91
  flow_type: AuthFlowType = "implicit",
92
+ verify: bool = True,
88
93
  ) -> None:
89
94
  AsyncGoTrueBaseAPI.__init__(
90
95
  self,
91
96
  url=url or GOTRUE_URL,
92
97
  headers=headers or DEFAULT_HEADERS,
93
98
  http_client=http_client,
99
+ verify=verify,
94
100
  )
95
101
  self._storage_key = storage_key or STORAGE_KEY
96
102
  self._auto_refresh_token = auto_refresh_token
@@ -253,6 +259,63 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
253
259
  self._notify_all_subscribers("SIGNED_IN", response.session)
254
260
  return response
255
261
 
262
+ async def sign_in_with_sso(self, credentials: SignInWithSSOCredentials):
263
+ """
264
+ Attempts a single-sign on using an enterprise Identity Provider. A
265
+ successful SSO attempt will redirect the current page to the identity
266
+ provider authorization page. The redirect URL is implementation and SSO
267
+ protocol specific.
268
+
269
+ You can use it by providing a SSO domain. Typically you can extract this
270
+ domain by asking users for their email address. If this domain is
271
+ registered on the Auth instance the redirect will use that organization's
272
+ currently active SSO Identity Provider for the login.
273
+ If you have built an organization-specific login page, you can use the
274
+ organization's SSO Identity Provider UUID directly instead.
275
+ """
276
+ self._remove_session()
277
+ provider_id = credentials.get("provider_id")
278
+ domain = credentials.get("domain")
279
+ options = credentials.get("options", {})
280
+ redirect_to = options.get("redirect_to")
281
+ captcha_token = options.get("captcha_token")
282
+ # HTTPX currently does not follow redirects: https://www.python-httpx.org/compatibility/
283
+ # Additionally, unlike the JS client, Python is a server side language and it's not possible
284
+ # to automatically redirect in browser for hte user
285
+ skip_http_redirect = options.get("skip_http_redirect", True)
286
+
287
+ if domain:
288
+ return self._request(
289
+ "POST",
290
+ "sso",
291
+ body={
292
+ "domain": domain,
293
+ "skip_http_redirect": skip_http_redirect,
294
+ "gotrue_meta_security": {
295
+ "captcha_token": captcha_token,
296
+ },
297
+ },
298
+ redirect_to=redirect_to,
299
+ xform=parse_sso_response,
300
+ )
301
+ if provider_id:
302
+ return self._request(
303
+ "POST",
304
+ "sso",
305
+ body={
306
+ "provider_id": provider_id,
307
+ "skip_http_redirect": skip_http_redirect,
308
+ "gotrue_meta_security": {
309
+ "captcha_token": captcha_token,
310
+ },
311
+ },
312
+ redirect_to=redirect_to,
313
+ xform=parse_sso_response,
314
+ )
315
+ raise AuthInvalidCredentialsError(
316
+ "You must provide either a domain or provider_id"
317
+ )
318
+
256
319
  async def sign_in_with_oauth(
257
320
  self,
258
321
  credentials: SignInWithOAuthCredentials,
@@ -274,10 +337,39 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
274
337
  url = await self._get_url_for_provider(provider, params)
275
338
  return OAuthResponse(provider=provider, url=url)
276
339
 
340
+ async def link_identity(self, credentials):
341
+ provider = credentials.get("provider")
342
+ options = credentials.get("options", {})
343
+ redirect_to = options.get("redirect_to")
344
+ scopes = options.get("scopes")
345
+ params = options.get("query_params", {})
346
+ if redirect_to:
347
+ params["redirect_to"] = redirect_to
348
+ if scopes:
349
+ params["scopes"] = scopes
350
+ params["skip_browser_redirect"] = True
351
+
352
+ url = await self._get_url_for_provider(provider, params)
353
+ return OAuthResponse(provider=provider, url=url)
354
+
355
+ async def get_user_identities(self):
356
+ response = self.get_user()
357
+ return (
358
+ IdentitiesResponse(identities=response.user.identities)
359
+ if response.user
360
+ else AuthSessionMissingError()
361
+ )
362
+
363
+ async def unlink_identity(self, identity):
364
+ return await self._request(
365
+ "POST",
366
+ f"/user/identities/{identity.id}",
367
+ )
368
+
277
369
  async def sign_in_with_otp(
278
370
  self,
279
371
  credentials: SignInWithPasswordlessCredentials,
280
- ) -> AuthResponse:
372
+ ) -> AuthOtpResponse:
281
373
  """
282
374
  Log in a user using magiclink or a one-time password (OTP).
283
375
 
@@ -311,7 +403,7 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
311
403
  },
312
404
  },
313
405
  redirect_to=email_redirect_to,
314
- xform=parse_auth_response,
406
+ xform=parse_auth_otp_response,
315
407
  )
316
408
  if phone:
317
409
  return await self._request(
@@ -325,7 +417,7 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
325
417
  "captcha_token": captcha_token,
326
418
  },
327
419
  },
328
- xform=parse_auth_response,
420
+ xform=parse_auth_otp_response,
329
421
  )
330
422
  raise AuthInvalidCredentialsError(
331
423
  "You must provide either an email or phone number"
@@ -6,16 +6,13 @@ from typing import Dict, Optional
6
6
 
7
7
  class AsyncSupportedStorage(ABC):
8
8
  @abstractmethod
9
- async def get_item(self, key: str) -> Optional[str]:
10
- ... # pragma: no cover
9
+ async def get_item(self, key: str) -> Optional[str]: ... # pragma: no cover
11
10
 
12
11
  @abstractmethod
13
- async def set_item(self, key: str, value: str) -> None:
14
- ... # pragma: no cover
12
+ async def set_item(self, key: str, value: str) -> None: ... # pragma: no cover
15
13
 
16
14
  @abstractmethod
17
- async def remove_item(self, key: str) -> None:
18
- ... # pragma: no cover
15
+ async def remove_item(self, key: str) -> None: ... # pragma: no cover
19
16
 
20
17
 
21
18
  class AsyncMemoryStorage(AsyncSupportedStorage):
@@ -26,12 +26,13 @@ class SyncGoTrueAPI:
26
26
  headers: Dict[str, str],
27
27
  cookie_options: CookieOptions,
28
28
  http_client: Optional[SyncClient] = None,
29
+ verify: bool = True,
29
30
  ) -> None:
30
31
  """Initialise API class."""
31
32
  self.url = url
32
33
  self.headers = headers
33
34
  self.cookie_options = cookie_options
34
- self.http_client = http_client or SyncClient()
35
+ self.http_client = http_client or SyncClient(verify=bool(verify))
35
36
 
36
37
  def __enter__(self) -> SyncGoTrueAPI:
37
38
  return self
@@ -136,8 +137,8 @@ class SyncGoTrueAPI:
136
137
  data = {"email": email, "password": password, "data": data}
137
138
  url = f"{self.url}/signup{query_string}"
138
139
  response = self.http_client.post(url, json=data, headers=headers)
139
- SessionOrUserModel = determine_session_or_user_model_from_response(response)
140
- return SessionOrUserModel.parse_response(response)
140
+ session_or_user_model = determine_session_or_user_model_from_response(response)
141
+ return session_or_user_model.parse_response(response)
141
142
 
142
143
  def sign_in_with_email(
143
144
  self,
@@ -211,8 +212,8 @@ class SyncGoTrueAPI:
211
212
  data = {"phone": phone, "password": password, "data": data}
212
213
  url = f"{self.url}/signup"
213
214
  response = self.http_client.post(url, json=data, headers=headers)
214
- SessionOrUserModel = determine_session_or_user_model_from_response(response)
215
- return SessionOrUserModel.parse_response(response)
215
+ session_or_user_model = determine_session_or_user_model_from_response(response)
216
+ return session_or_user_model.parse_response(response)
216
217
 
217
218
  def sign_in_with_phone(
218
219
  self,
@@ -335,8 +336,8 @@ class SyncGoTrueAPI:
335
336
  data["redirect_to"] = redirect_to_encoded
336
337
  url = f"{self.url}/verify"
337
338
  response = self.http_client.post(url, json=data, headers=headers)
338
- SessionOrUserModel = determine_session_or_user_model_from_response(response)
339
- return SessionOrUserModel.parse_response(response)
339
+ session_or_user_model = determine_session_or_user_model_from_response(response)
340
+ return session_or_user_model.parse_response(response)
340
341
 
341
342
  def invite_user_by_email(
342
343
  self,
@@ -637,8 +638,8 @@ class SyncGoTrueAPI:
637
638
  data["redirect_to"] = redirect_to_encoded
638
639
  url = f"{self.url}/admin/generate_link"
639
640
  response = self.http_client.post(url, json=data, headers=headers)
640
- SessionOrUserModel = determine_session_or_user_model_from_response(response)
641
- return SessionOrUserModel.parse_response(response)
641
+ session_or_user_model = determine_session_or_user_model_from_response(response)
642
+ return session_or_user_model.parse_response(response)
642
643
 
643
644
  def set_auth_cookie(self, *, req, res):
644
645
  """Stub for parity with JS api."""
@@ -37,6 +37,7 @@ class SyncGoTrueClient:
37
37
  cookie_options: CookieOptions = CookieOptions.parse_obj(COOKIE_OPTIONS),
38
38
  api: Optional[SyncGoTrueAPI] = None,
39
39
  replace_default_headers: bool = False,
40
+ verify: bool = True,
40
41
  ) -> None:
41
42
  """Create a new client
42
43
 
@@ -54,6 +55,8 @@ class SyncGoTrueClient:
54
55
  The storage engine to use for persisting the session.
55
56
  cookie_options : CookieOptions
56
57
  The options for the cookie.
58
+ verify: bool
59
+ Verify SSL, True by default, False disables verification.
57
60
  """
58
61
  if url.startswith("http://"):
59
62
  print(
@@ -72,6 +75,7 @@ class SyncGoTrueClient:
72
75
  "url": url,
73
76
  "headers": {**empty_or_default_headers, **headers},
74
77
  "cookie_options": cookie_options,
78
+ "verify": verify,
75
79
  }
76
80
  self.api = api or SyncGoTrueAPI(**args)
77
81
 
@@ -29,12 +29,14 @@ class SyncGoTrueAdminAPI(SyncGoTrueBaseAPI):
29
29
  url: str = "",
30
30
  headers: Dict[str, str] = {},
31
31
  http_client: Union[SyncClient, None] = None,
32
+ verify: bool = True,
32
33
  ) -> None:
33
34
  SyncGoTrueBaseAPI.__init__(
34
35
  self,
35
36
  url=url,
36
37
  headers=headers,
37
38
  http_client=http_client,
39
+ verify=verify,
38
40
  )
39
41
  self.mfa = SyncGoTrueAdminMFAAPI()
40
42
  self.mfa.list_factors = self._list_factors
@@ -113,9 +115,11 @@ class SyncGoTrueAdminAPI(SyncGoTrueBaseAPI):
113
115
  "GET",
114
116
  "admin/users",
115
117
  query={"page": page, "per_page": per_page},
116
- xform=lambda data: [model_validate(User, user) for user in data["users"]]
117
- if "users" in data
118
- else [],
118
+ xform=lambda data: (
119
+ [model_validate(User, user) for user in data["users"]]
120
+ if "users" in data
121
+ else []
122
+ ),
119
123
  )
120
124
 
121
125
  def get_user_by_id(self, uid: str) -> UserResponse:
@@ -19,10 +19,11 @@ class SyncGoTrueBaseAPI:
19
19
  url: str,
20
20
  headers: Dict[str, str],
21
21
  http_client: Union[SyncClient, None],
22
+ verify: bool = True,
22
23
  ):
23
24
  self._url = url
24
25
  self._headers = headers
25
- self._http_client = http_client or SyncClient()
26
+ self._http_client = http_client or SyncClient(verify=bool(verify))
26
27
 
27
28
  def __enter__(self) -> Self:
28
29
  return self
@@ -46,8 +47,7 @@ class SyncGoTrueBaseAPI:
46
47
  body: Union[Any, None] = None,
47
48
  no_resolve_json: Literal[False] = False,
48
49
  xform: Callable[[Any], T],
49
- ) -> T:
50
- ... # pragma: no cover
50
+ ) -> T: ... # pragma: no cover
51
51
 
52
52
  @overload
53
53
  def _request(
@@ -62,8 +62,7 @@ class SyncGoTrueBaseAPI:
62
62
  body: Union[Any, None] = None,
63
63
  no_resolve_json: Literal[True],
64
64
  xform: Callable[[Response], T],
65
- ) -> T:
66
- ... # pragma: no cover
65
+ ) -> T: ... # pragma: no cover
67
66
 
68
67
  @overload
69
68
  def _request(
@@ -77,8 +76,7 @@ class SyncGoTrueBaseAPI:
77
76
  query: Union[Dict[str, str], None] = None,
78
77
  body: Union[Any, None] = None,
79
78
  no_resolve_json: bool = False,
80
- ) -> None:
81
- ... # pragma: no cover
79
+ ) -> None: ... # pragma: no cover
82
80
 
83
81
  def _request(
84
82
  self,
@@ -30,7 +30,9 @@ from ..helpers import (
30
30
  model_dump,
31
31
  model_dump_json,
32
32
  model_validate,
33
+ parse_auth_otp_response,
33
34
  parse_auth_response,
35
+ parse_sso_response,
34
36
  parse_user_response,
35
37
  )
36
38
  from ..http_clients import SyncClient
@@ -45,9 +47,11 @@ from ..types import (
45
47
  AuthMFAListFactorsResponse,
46
48
  AuthMFAUnenrollResponse,
47
49
  AuthMFAVerifyResponse,
50
+ AuthOtpResponse,
48
51
  AuthResponse,
49
52
  CodeExchangeParams,
50
53
  DecodedJWTDict,
54
+ IdentitiesResponse,
51
55
  MFAChallengeAndVerifyParams,
52
56
  MFAChallengeParams,
53
57
  MFAEnrollParams,
@@ -85,12 +89,14 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
85
89
  storage: Union[SyncSupportedStorage, None] = None,
86
90
  http_client: Union[SyncClient, None] = None,
87
91
  flow_type: AuthFlowType = "implicit",
92
+ verify: bool = True,
88
93
  ) -> None:
89
94
  SyncGoTrueBaseAPI.__init__(
90
95
  self,
91
96
  url=url or GOTRUE_URL,
92
97
  headers=headers or DEFAULT_HEADERS,
93
98
  http_client=http_client,
99
+ verify=verify,
94
100
  )
95
101
  self._storage_key = storage_key or STORAGE_KEY
96
102
  self._auto_refresh_token = auto_refresh_token
@@ -253,6 +259,63 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
253
259
  self._notify_all_subscribers("SIGNED_IN", response.session)
254
260
  return response
255
261
 
262
+ def sign_in_with_sso(self, credentials: SignInWithSSOCredentials):
263
+ """
264
+ Attempts a single-sign on using an enterprise Identity Provider. A
265
+ successful SSO attempt will redirect the current page to the identity
266
+ provider authorization page. The redirect URL is implementation and SSO
267
+ protocol specific.
268
+
269
+ You can use it by providing a SSO domain. Typically you can extract this
270
+ domain by asking users for their email address. If this domain is
271
+ registered on the Auth instance the redirect will use that organization's
272
+ currently active SSO Identity Provider for the login.
273
+ If you have built an organization-specific login page, you can use the
274
+ organization's SSO Identity Provider UUID directly instead.
275
+ """
276
+ self._remove_session()
277
+ provider_id = credentials.get("provider_id")
278
+ domain = credentials.get("domain")
279
+ options = credentials.get("options", {})
280
+ redirect_to = options.get("redirect_to")
281
+ captcha_token = options.get("captcha_token")
282
+ # HTTPX currently does not follow redirects: https://www.python-httpx.org/compatibility/
283
+ # Additionally, unlike the JS client, Python is a server side language and it's not possible
284
+ # to automatically redirect in browser for hte user
285
+ skip_http_redirect = options.get("skip_http_redirect", True)
286
+
287
+ if domain:
288
+ return self._request(
289
+ "POST",
290
+ "sso",
291
+ body={
292
+ "domain": domain,
293
+ "skip_http_redirect": skip_http_redirect,
294
+ "gotrue_meta_security": {
295
+ "captcha_token": captcha_token,
296
+ },
297
+ },
298
+ redirect_to=redirect_to,
299
+ xform=parse_sso_response,
300
+ )
301
+ if provider_id:
302
+ return self._request(
303
+ "POST",
304
+ "sso",
305
+ body={
306
+ "provider_id": provider_id,
307
+ "skip_http_redirect": skip_http_redirect,
308
+ "gotrue_meta_security": {
309
+ "captcha_token": captcha_token,
310
+ },
311
+ },
312
+ redirect_to=redirect_to,
313
+ xform=parse_sso_response,
314
+ )
315
+ raise AuthInvalidCredentialsError(
316
+ "You must provide either a domain or provider_id"
317
+ )
318
+
256
319
  def sign_in_with_oauth(
257
320
  self,
258
321
  credentials: SignInWithOAuthCredentials,
@@ -274,10 +337,39 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
274
337
  url = self._get_url_for_provider(provider, params)
275
338
  return OAuthResponse(provider=provider, url=url)
276
339
 
340
+ def link_identity(self, credentials):
341
+ provider = credentials.get("provider")
342
+ options = credentials.get("options", {})
343
+ redirect_to = options.get("redirect_to")
344
+ scopes = options.get("scopes")
345
+ params = options.get("query_params", {})
346
+ if redirect_to:
347
+ params["redirect_to"] = redirect_to
348
+ if scopes:
349
+ params["scopes"] = scopes
350
+ params["skip_browser_redirect"] = True
351
+
352
+ url = self._get_url_for_provider(provider, params)
353
+ return OAuthResponse(provider=provider, url=url)
354
+
355
+ def get_user_identities(self):
356
+ response = self.get_user()
357
+ return (
358
+ IdentitiesResponse(identities=response.user.identities)
359
+ if response.user
360
+ else AuthSessionMissingError()
361
+ )
362
+
363
+ def unlink_identity(self, identity):
364
+ return self._request(
365
+ "POST",
366
+ f"/user/identities/{identity.id}",
367
+ )
368
+
277
369
  def sign_in_with_otp(
278
370
  self,
279
371
  credentials: SignInWithPasswordlessCredentials,
280
- ) -> AuthResponse:
372
+ ) -> AuthOtpResponse:
281
373
  """
282
374
  Log in a user using magiclink or a one-time password (OTP).
283
375
 
@@ -311,7 +403,7 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
311
403
  },
312
404
  },
313
405
  redirect_to=email_redirect_to,
314
- xform=parse_auth_response,
406
+ xform=parse_auth_otp_response,
315
407
  )
316
408
  if phone:
317
409
  return self._request(
@@ -325,7 +417,7 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
325
417
  "captcha_token": captcha_token,
326
418
  },
327
419
  },
328
- xform=parse_auth_response,
420
+ xform=parse_auth_otp_response,
329
421
  )
330
422
  raise AuthInvalidCredentialsError(
331
423
  "You must provide either an email or phone number"
@@ -6,16 +6,13 @@ from typing import Dict, Optional
6
6
 
7
7
  class SyncSupportedStorage(ABC):
8
8
  @abstractmethod
9
- def get_item(self, key: str) -> Optional[str]:
10
- ... # pragma: no cover
9
+ def get_item(self, key: str) -> Optional[str]: ... # pragma: no cover
11
10
 
12
11
  @abstractmethod
13
- def set_item(self, key: str, value: str) -> None:
14
- ... # pragma: no cover
12
+ def set_item(self, key: str, value: str) -> None: ... # pragma: no cover
15
13
 
16
14
  @abstractmethod
17
- def remove_item(self, key: str) -> None:
18
- ... # pragma: no cover
15
+ def remove_item(self, key: str) -> None: ... # pragma: no cover
19
16
 
20
17
 
21
18
  class SyncMemoryStorage(SyncSupportedStorage):
@@ -13,10 +13,12 @@ from pydantic import BaseModel
13
13
 
14
14
  from .errors import AuthApiError, AuthError, AuthRetryableError, AuthUnknownError
15
15
  from .types import (
16
+ AuthOtpResponse,
16
17
  AuthResponse,
17
18
  GenerateLinkProperties,
18
19
  GenerateLinkResponse,
19
20
  Session,
21
+ SSOResponse,
20
22
  User,
21
23
  UserResponse,
22
24
  )
@@ -71,6 +73,10 @@ def parse_auth_response(data: Any) -> AuthResponse:
71
73
  return AuthResponse(session=session, user=user)
72
74
 
73
75
 
76
+ def parse_auth_otp_response(data: Any) -> AuthOtpResponse:
77
+ return model_validate(AuthOtpResponse, data)
78
+
79
+
74
80
  def parse_link_response(data: Any) -> GenerateLinkResponse:
75
81
  properties = GenerateLinkProperties(
76
82
  action_link=data.get("action_link"),
@@ -91,10 +97,14 @@ def parse_user_response(data: Any) -> UserResponse:
91
97
  return model_validate(UserResponse, data)
92
98
 
93
99
 
100
+ def parse_sso_response(data: Any) -> SSOResponse:
101
+ return model_validate(SSOResponse, data)
102
+
103
+
94
104
  def get_error_message(error: Any) -> str:
95
105
  props = ["msg", "message", "error_description", "error"]
96
- filter = (
97
- lambda prop: prop in error if isinstance(error, dict) else hasattr(error, prop)
106
+ filter = lambda prop: (
107
+ prop in error if isinstance(error, dict) else hasattr(error, prop)
98
108
  )
99
109
  return next((error[prop] for prop in props if filter(prop)), str(error))
100
110
 
@@ -123,11 +133,11 @@ def decode_jwt_payload(token: str) -> Any:
123
133
  parts = token.split(".")
124
134
  if len(parts) != 3:
125
135
  raise ValueError("JWT is not valid: not a JWT structure")
126
- base64Url = parts[1]
136
+ base64url = parts[1]
127
137
  # Addding padding otherwise the following error happens:
128
138
  # binascii.Error: Incorrect padding
129
- base64UrlWithPadding = base64Url + "=" * (-len(base64Url) % 4)
130
- return loads(urlsafe_b64decode(base64UrlWithPadding).decode("utf-8"))
139
+ base64url_with_padding = base64url + "=" * (-len(base64url) % 4)
140
+ return loads(urlsafe_b64decode(base64url_with_padding).decode("utf-8"))
131
141
 
132
142
 
133
143
  def generate_pkce_verifier(length=64):
@@ -89,11 +89,25 @@ class AuthResponse(BaseModel):
89
89
  session: Union[Session, None] = None
90
90
 
91
91
 
92
+ class AuthOtpResponse(BaseModel):
93
+ user: None = None
94
+ session: None = None
95
+ message_id: Union[str, None] = None
96
+
97
+
92
98
  class OAuthResponse(BaseModel):
93
99
  provider: Provider
94
100
  url: str
95
101
 
96
102
 
103
+ class SSOResponse(BaseModel):
104
+ url: str
105
+
106
+
107
+ class IdentitiesResponse(BaseModel):
108
+ identities: List[UserIdentity]
109
+
110
+
97
111
  class UserResponse(BaseModel):
98
112
  user: User
99
113
 
@@ -323,6 +337,17 @@ class SignInWithOAuthCredentials(TypedDict):
323
337
  options: NotRequired[SignInWithOAuthCredentialsOptions]
324
338
 
325
339
 
340
+ class SignInWithSSOCredentials(TypedDict):
341
+ provider_id: NotRequired[str]
342
+ domain: NotRequired[str]
343
+ options: NotRequired[SignInWithSSOOptions]
344
+
345
+
346
+ class SignInWithSSOOptions(TypedDict):
347
+ redirect_to: NotRequired[str]
348
+ skip_http_redirect: NotRequired[bool]
349
+
350
+
326
351
  class VerifyOtpParamsOptions(TypedDict):
327
352
  redirect_to: NotRequired[str]
328
353
  captcha_token: NotRequired[str]
File without changes