supabase_auth 2.12.0__tar.gz → 2.12.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 (29) hide show
  1. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/PKG-INFO +92 -32
  2. supabase_auth-2.12.3/README.md +159 -0
  3. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/pyproject.toml +30 -12
  4. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/__init__.py +8 -4
  5. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_async/gotrue_admin_api.py +18 -2
  6. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_async/gotrue_client.py +9 -5
  7. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_sync/gotrue_admin_api.py +18 -2
  8. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_sync/gotrue_client.py +9 -5
  9. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/helpers.py +9 -23
  10. supabase_auth-2.12.3/supabase_auth/py.typed +0 -0
  11. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/types.py +10 -3
  12. supabase_auth-2.12.3/supabase_auth/version.py +1 -0
  13. supabase_auth-2.12.0/README.md +0 -98
  14. supabase_auth-2.12.0/supabase_auth/version.py +0 -1
  15. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/LICENSE +0 -0
  16. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_async/__init__.py +0 -0
  17. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_async/gotrue_admin_mfa_api.py +0 -0
  18. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_async/gotrue_base_api.py +0 -0
  19. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_async/gotrue_mfa_api.py +0 -0
  20. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_async/storage.py +0 -0
  21. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_sync/__init__.py +0 -0
  22. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_sync/gotrue_admin_mfa_api.py +0 -0
  23. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_sync/gotrue_base_api.py +0 -0
  24. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_sync/gotrue_mfa_api.py +0 -0
  25. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/_sync/storage.py +0 -0
  26. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/constants.py +0 -0
  27. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/errors.py +0 -0
  28. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/http_clients.py +0 -0
  29. {supabase_auth-2.12.0 → supabase_auth-2.12.3}/supabase_auth/timer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supabase_auth
3
- Version: 2.12.0
3
+ Version: 2.12.3
4
4
  Summary: Python Client Library for Supabase Auth
5
5
  Home-page: https://github.com/supabase/auth-py
6
6
  License: MIT
@@ -18,30 +18,22 @@ Classifier: Programming Language :: Python :: 3.13
18
18
  Requires-Dist: httpx[http2] (>=0.26,<0.29)
19
19
  Requires-Dist: pydantic (>=1.10,<3)
20
20
  Requires-Dist: pyjwt (>=2.10.1,<3.0.0)
21
- Requires-Dist: pytest-mock (>=3.14.0,<4.0.0)
22
21
  Project-URL: Documentation, https://github.com/supabase/auth-py
23
22
  Project-URL: Repository, https://github.com/supabase/auth-py
24
23
  Description-Content-Type: text/markdown
25
24
 
26
25
  # Auth-py
27
26
 
28
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?label=license)](https://opensource.org/licenses/MIT)
29
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)
30
28
  [![Python](https://img.shields.io/pypi/pyversions/gotrue)](https://pypi.org/project/gotrue)
31
29
  [![Version](https://img.shields.io/pypi/v/gotrue?color=%2334D058)](https://pypi.org/project/gotrue)
32
- [![Codecov](https://codecov.io/gh/supabase-community/gotrue-py/branch/main/graph/badge.svg)](https://codecov.io/gh/supabase-community/gotrue-py)
33
- [![Last commit](https://img.shields.io/github/last-commit/supabase-community/gotrue-py.svg?style=flat)](https://github.com/supabase-community/gotrue-py/commits)
34
- [![GitHub commit activity](https://img.shields.io/github/commit-activity/m/supabase-community/gotrue-py)](https://github.com/supabase-community/gotrue-py/commits)
35
- [![Github Stars](https://img.shields.io/github/stars/supabase-community/gotrue-py?style=flat&logo=github)](https://github.com/supabase-community/gotrue-py/stargazers)
36
- [![Github Forks](https://img.shields.io/github/forks/supabase-community/gotrue-py?style=flat&logo=github)](https://github.com/supabase-community/gotrue-py/network/members)
37
- [![Github Watchers](https://img.shields.io/github/watchers/supabase-community/gotrue-py?style=flat&logo=github)](https://github.com/supabase-community/gotrue-py)
38
- [![GitHub contributors](https://img.shields.io/github/contributors/supabase-community/gotrue-py)](https://github.com/supabase-community/gotrue-py/graphs/contributors)
30
+ [![Coverage Status](https://coveralls.io/repos/github/supabase/auth-py/badge.svg?branch=main)](https://coveralls.io/github/supabase/auth-py?branch=main)
39
31
 
40
32
  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.
41
33
 
42
34
  ## Installation
43
35
 
44
- 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.
36
+ The package can be installed using pip or poetry:
45
37
 
46
38
  ### Poetry
47
39
 
@@ -55,6 +47,19 @@ poetry add supabase_auth
55
47
  pip install supabase_auth
56
48
  ```
57
49
 
50
+ ## Features
51
+
52
+ - Full feature parity with the JavaScript client
53
+ - Support for both synchronous and asynchronous operations
54
+ - MFA (Multi-Factor Authentication) support
55
+ - OAuth and SSO integration
56
+ - Magic link and OTP authentication
57
+ - Phone number authentication
58
+ - Anonymous sign-in
59
+ - Session management with auto-refresh
60
+ - JWT token handling and verification
61
+ - User management and profile updates
62
+
58
63
  ## Differences to the JS client
59
64
 
60
65
  It should be noted there are differences to the [JS client](https://github.com/supabase/gotrue-js). If you feel particulaly strongly about them and want to motivate a change, feel free to make a GitHub issue and we can discuss it there.
@@ -73,11 +78,11 @@ The other key difference is we do not use pascalCase to encode variable and meth
73
78
 
74
79
  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.
75
80
 
76
- ## Usage (outdated)
81
+ ## Usage
77
82
 
78
- **Important:** This section is outdated, you can be guided by the [JS client documentation](https://supabase.github.io/gotrue-js) because this Python client has a lot of parity with the JS client.
83
+ The library provides both synchronous and asynchronous clients. Here are some examples:
79
84
 
80
- To instantiate the client, you'll need the URL and any request headers at a minimum.
85
+ ### Synchronous Client
81
86
 
82
87
  ```python
83
88
  from supabase_auth import SyncGoTrueClient
@@ -87,38 +92,93 @@ headers = {
87
92
  # ... any other headers you might need.
88
93
  }
89
94
  client: SyncGoTrueClient = SyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)
90
- ```
91
95
 
92
- To send a magic email link to the user, just provide the email kwarg to the `sign_in` method:
96
+ # Sign up with email and password
97
+ user = client.sign_up(email="example@gmail.com", password="*********")
93
98
 
94
- ```python
95
- user: Dict[str, Any] = client.sign_up(email="example@gmail.com")
96
- ```
99
+ # Sign in with email and password
100
+ user = client.sign_in_with_password(email="example@gmail.com", password="*********")
97
101
 
98
- To login with email and password, provide both to the `sign_in` method:
102
+ # Sign in with magic link
103
+ user = client.sign_in_with_otp(email="example@gmail.com")
99
104
 
100
- ```python
101
- user: Dict[str, Any] = client.sign_up(email="example@gmail.com", password="*********")
105
+ # Sign in with phone number
106
+ user = client.sign_in_with_otp(phone="+1234567890")
107
+
108
+ # Sign in with OAuth
109
+ user = client.sign_in_with_oauth(provider="google")
110
+
111
+ # Sign out
112
+ client.sign_out()
113
+
114
+ # Get current user
115
+ user = client.get_user()
116
+
117
+ # Update user profile
118
+ user = client.update_user({"data": {"name": "John Doe"}})
102
119
  ```
103
120
 
104
- To sign out of the logged in user, call the `sign_out` method. We can then assert that the session and user are null values.
121
+ ### Asynchronous Client
105
122
 
106
123
  ```python
107
- client.sign_out()
108
- assert client.user() is None
109
- assert client.session() is None
124
+ from supabase_auth import AsyncGoTrueClient
125
+
126
+ headers = {
127
+ "apiKey": "my-mega-awesome-api-key",
128
+ # ... any other headers you might need.
129
+ }
130
+ client: AsyncGoTrueClient = AsyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)
131
+
132
+ async def main():
133
+ # Sign up with email and password
134
+ user = await client.sign_up(email="example@gmail.com", password="*********")
135
+
136
+ # Sign in with email and password
137
+ user = await client.sign_in_with_password(email="example@gmail.com", password="*********")
138
+
139
+ # Sign in with magic link
140
+ user = await client.sign_in_with_otp(email="example@gmail.com")
141
+
142
+ # Sign in with phone number
143
+ user = await client.sign_in_with_otp(phone="+1234567890")
144
+
145
+ # Sign in with OAuth
146
+ user = await client.sign_in_with_oauth(provider="google")
147
+
148
+ # Sign out
149
+ await client.sign_out()
150
+
151
+ # Get current user
152
+ user = await client.get_user()
153
+
154
+ # Update user profile
155
+ user = await client.update_user({"data": {"name": "John Doe"}})
156
+
157
+ # Run the async code
158
+ import asyncio
159
+ asyncio.run(main())
110
160
  ```
111
161
 
112
- We can refesh a users session.
162
+ ### MFA Support
163
+
164
+ The library includes support for Multi-Factor Authentication:
113
165
 
114
166
  ```python
115
- # The user should already be signed in at this stage.
116
- user = client.refresh_session()
117
- assert client.user() is not None
118
- assert client.session() is not None
167
+ # List MFA factors
168
+ factors = client.mfa.list_factors()
169
+
170
+ # Enroll a new MFA factor
171
+ enrolled_factor = client.mfa.enroll({"factor_type": "totp"})
172
+
173
+ # Challenge and verify MFA
174
+ challenge = client.mfa.challenge({"factor_id": "factor_id"})
175
+ verified = client.mfa.verify({"factor_id": "factor_id", "code": "123456"})
176
+
177
+ # Unenroll a factor
178
+ client.mfa.unenroll({"factor_id": "factor_id"})
119
179
  ```
120
180
 
121
181
  ## Contributions
122
182
 
123
- We would be immensely grateful for any contributions to this project.
183
+ We would be immensely grateful for any contributions to this project.
124
184
 
@@ -0,0 +1,159 @@
1
+ # Auth-py
2
+
3
+ [![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)
4
+ [![Python](https://img.shields.io/pypi/pyversions/gotrue)](https://pypi.org/project/gotrue)
5
+ [![Version](https://img.shields.io/pypi/v/gotrue?color=%2334D058)](https://pypi.org/project/gotrue)
6
+ [![Coverage Status](https://coveralls.io/repos/github/supabase/auth-py/badge.svg?branch=main)](https://coveralls.io/github/supabase/auth-py?branch=main)
7
+
8
+ 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.
9
+
10
+ ## Installation
11
+
12
+ The package can be installed using pip or poetry:
13
+
14
+ ### Poetry
15
+
16
+ ```bash
17
+ poetry add supabase_auth
18
+ ```
19
+
20
+ ### Pip
21
+
22
+ ```bash
23
+ pip install supabase_auth
24
+ ```
25
+
26
+ ## Features
27
+
28
+ - Full feature parity with the JavaScript client
29
+ - Support for both synchronous and asynchronous operations
30
+ - MFA (Multi-Factor Authentication) support
31
+ - OAuth and SSO integration
32
+ - Magic link and OTP authentication
33
+ - Phone number authentication
34
+ - Anonymous sign-in
35
+ - Session management with auto-refresh
36
+ - JWT token handling and verification
37
+ - User management and profile updates
38
+
39
+ ## Differences to the JS client
40
+
41
+ It should be noted there are differences to the [JS client](https://github.com/supabase/gotrue-js). If you feel particulaly strongly about them and want to motivate a change, feel free to make a GitHub issue and we can discuss it there.
42
+
43
+ Firstly, feature pairity is not 100% with the [JS client](https://github.com/supabase/gotrue-js). In most cases we match the methods and attributes of the [JS client](https://github.com/supabase/gotrue-js) and api classes, but is some places (e.g for browser specific code) it didn't make sense to port the code line for line.
44
+
45
+ There is also a divergence in terms of how errors are raised. In the [JS client](https://github.com/supabase/gotrue-js), the errors are returned as part of the object, which the user can choose to process in whatever way they see fit. In this Python client, we raise the errors directly where they originate, as it was felt this was more Pythonic and adhered to the idioms of the language more directly.
46
+
47
+ In JS we return the error, but in Python we just raise it.
48
+
49
+ ```js
50
+ const { data, error } = client.sign_up(...)
51
+ ```
52
+
53
+ 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.
54
+
55
+ 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.
56
+
57
+ ## Usage
58
+
59
+ The library provides both synchronous and asynchronous clients. Here are some examples:
60
+
61
+ ### Synchronous Client
62
+
63
+ ```python
64
+ from supabase_auth import SyncGoTrueClient
65
+
66
+ headers = {
67
+ "apiKey": "my-mega-awesome-api-key",
68
+ # ... any other headers you might need.
69
+ }
70
+ client: SyncGoTrueClient = SyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)
71
+
72
+ # Sign up with email and password
73
+ user = client.sign_up(email="example@gmail.com", password="*********")
74
+
75
+ # Sign in with email and password
76
+ user = client.sign_in_with_password(email="example@gmail.com", password="*********")
77
+
78
+ # Sign in with magic link
79
+ user = client.sign_in_with_otp(email="example@gmail.com")
80
+
81
+ # Sign in with phone number
82
+ user = client.sign_in_with_otp(phone="+1234567890")
83
+
84
+ # Sign in with OAuth
85
+ user = client.sign_in_with_oauth(provider="google")
86
+
87
+ # Sign out
88
+ client.sign_out()
89
+
90
+ # Get current user
91
+ user = client.get_user()
92
+
93
+ # Update user profile
94
+ user = client.update_user({"data": {"name": "John Doe"}})
95
+ ```
96
+
97
+ ### Asynchronous Client
98
+
99
+ ```python
100
+ from supabase_auth import AsyncGoTrueClient
101
+
102
+ headers = {
103
+ "apiKey": "my-mega-awesome-api-key",
104
+ # ... any other headers you might need.
105
+ }
106
+ client: AsyncGoTrueClient = AsyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)
107
+
108
+ async def main():
109
+ # Sign up with email and password
110
+ user = await client.sign_up(email="example@gmail.com", password="*********")
111
+
112
+ # Sign in with email and password
113
+ user = await client.sign_in_with_password(email="example@gmail.com", password="*********")
114
+
115
+ # Sign in with magic link
116
+ user = await client.sign_in_with_otp(email="example@gmail.com")
117
+
118
+ # Sign in with phone number
119
+ user = await client.sign_in_with_otp(phone="+1234567890")
120
+
121
+ # Sign in with OAuth
122
+ user = await client.sign_in_with_oauth(provider="google")
123
+
124
+ # Sign out
125
+ await client.sign_out()
126
+
127
+ # Get current user
128
+ user = await client.get_user()
129
+
130
+ # Update user profile
131
+ user = await client.update_user({"data": {"name": "John Doe"}})
132
+
133
+ # Run the async code
134
+ import asyncio
135
+ asyncio.run(main())
136
+ ```
137
+
138
+ ### MFA Support
139
+
140
+ The library includes support for Multi-Factor Authentication:
141
+
142
+ ```python
143
+ # List MFA factors
144
+ factors = client.mfa.list_factors()
145
+
146
+ # Enroll a new MFA factor
147
+ enrolled_factor = client.mfa.enroll({"factor_type": "totp"})
148
+
149
+ # Challenge and verify MFA
150
+ challenge = client.mfa.challenge({"factor_id": "factor_id"})
151
+ verified = client.mfa.verify({"factor_id": "factor_id", "code": "123456"})
152
+
153
+ # Unenroll a factor
154
+ client.mfa.unenroll({"factor_id": "factor_id"})
155
+ ```
156
+
157
+ ## Contributions
158
+
159
+ We would be immensely grateful for any contributions to this project.
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "supabase_auth"
3
- version = "2.12.0" # {x-release-please-version}
3
+ version = "2.12.3" # {x-release-please-version}
4
4
  description = "Python Client Library for Supabase Auth"
5
5
  authors = ["Joel Lee <joel@joellee.org>"]
6
6
  homepage = "https://github.com/supabase/auth-py"
@@ -19,23 +19,41 @@ python = "^3.9"
19
19
  httpx = { version = ">=0.26,<0.29", extras = ["http2"] }
20
20
  pydantic = ">=1.10,<3"
21
21
  pyjwt = "^2.10.1"
22
- pytest-mock = "^3.14.0"
23
22
 
24
- [tool.poetry.dev-dependencies]
25
- pytest = "^8.3.5"
26
- flake8 = "^7.1.2"
27
- black = "^25.1.0"
28
- isort = "^6.0.1"
23
+ [tool.poetry.group.dev.dependencies]
24
+ pytest = "^8.4.1"
25
+ pytest-mock = "^3.14.0"
29
26
  pre-commit = "^4.2.0"
30
- pytest-cov = "^6.0.0"
27
+ pytest-cov = "^6.2.1"
31
28
  pytest-depends = "^1.0.1"
32
- pytest-asyncio = "^0.26.0"
33
- Faker = "^37.1.0"
29
+ pytest-asyncio = "^1.0.0"
30
+ Faker = "^37.4.0"
34
31
  unasync-cli = { git = "https://github.com/supabase-community/unasync-cli.git", branch = "main" }
35
-
36
- [tool.poetry.group.dev.dependencies]
37
32
  pygithub = ">=1.57,<3.0"
38
33
  respx = ">=0.20.2,<0.23.0"
34
+ ruff = "^0.12.1"
35
+
36
+ [tool.ruff.lint]
37
+ select = [
38
+ # pycodestyle
39
+ "E",
40
+ # Pyflakes
41
+ "F",
42
+ # pyupgrade
43
+ "UP",
44
+ # flake8-bugbear
45
+ # "B",
46
+ # flake8-simplify
47
+ # "SIM",
48
+ # isort
49
+ "I",
50
+ ]
51
+ ignore = ["F401", "F403", "F841", "E712", "E501", "E402", "E722", "E731", "UP006", "UP035"]
52
+ # isort.required-imports = ["from __future__ import annotations"]
53
+
54
+ [tool.ruff.lint.pyupgrade]
55
+ # Preserve types, even if a file imports `from __future__ import annotations`.
56
+ keep-runtime-typing = true
39
57
 
40
58
  [build-system]
41
59
  requires = ["poetry-core>=1.0.0"]
@@ -2,11 +2,15 @@ from __future__ import annotations
2
2
 
3
3
  from ._async.gotrue_admin_api import AsyncGoTrueAdminAPI # type: ignore # noqa: F401
4
4
  from ._async.gotrue_client import AsyncGoTrueClient # type: ignore # noqa: F401
5
- from ._async.storage import AsyncMemoryStorage # type: ignore # noqa: F401
6
- from ._async.storage import AsyncSupportedStorage # type: ignore # noqa: F401
5
+ from ._async.storage import (
6
+ AsyncMemoryStorage, # type: ignore # noqa: F401
7
+ AsyncSupportedStorage, # type: ignore # noqa: F401
8
+ )
7
9
  from ._sync.gotrue_admin_api import SyncGoTrueAdminAPI # type: ignore # noqa: F401
8
10
  from ._sync.gotrue_client import SyncGoTrueClient # type: ignore # noqa: F401
9
- from ._sync.storage import SyncMemoryStorage # type: ignore # noqa: F401
10
- from ._sync.storage import SyncSupportedStorage # type: ignore # noqa: F401
11
+ from ._sync.storage import (
12
+ SyncMemoryStorage, # type: ignore # noqa: F401
13
+ SyncSupportedStorage, # type: ignore # noqa: F401
14
+ )
11
15
  from .types import * # type: ignore # noqa: F401, F403
12
16
  from .version import __version__
@@ -3,7 +3,12 @@ from __future__ import annotations
3
3
  from functools import partial
4
4
  from typing import Dict, List, Optional
5
5
 
6
- from ..helpers import model_validate, parse_link_response, parse_user_response
6
+ from ..helpers import (
7
+ is_valid_uuid,
8
+ model_validate,
9
+ parse_link_response,
10
+ parse_user_response,
11
+ )
7
12
  from ..http_clients import AsyncClient
8
13
  from ..types import (
9
14
  AdminUserAttributes,
@@ -131,6 +136,8 @@ class AsyncGoTrueAdminAPI(AsyncGoTrueBaseAPI):
131
136
  This function should only be called on a server.
132
137
  Never expose your `service_role` key in the browser.
133
138
  """
139
+ self._validate_uuid(uid)
140
+
134
141
  return await self._request(
135
142
  "GET",
136
143
  f"admin/users/{uid}",
@@ -148,6 +155,7 @@ class AsyncGoTrueAdminAPI(AsyncGoTrueBaseAPI):
148
155
  This function should only be called on a server.
149
156
  Never expose your `service_role` key in the browser.
150
157
  """
158
+ self._validate_uuid(uid)
151
159
  return await self._request(
152
160
  "PUT",
153
161
  f"admin/users/{uid}",
@@ -162,6 +170,7 @@ class AsyncGoTrueAdminAPI(AsyncGoTrueBaseAPI):
162
170
  This function should only be called on a server.
163
171
  Never expose your `service_role` key in the browser.
164
172
  """
173
+ self._validate_uuid(id)
165
174
  body = {"should_soft_delete": should_soft_delete}
166
175
  return await self._request("DELETE", f"admin/users/{id}", body=body)
167
176
 
@@ -169,6 +178,7 @@ class AsyncGoTrueAdminAPI(AsyncGoTrueBaseAPI):
169
178
  self,
170
179
  params: AuthMFAAdminListFactorsParams,
171
180
  ) -> AuthMFAAdminListFactorsResponse:
181
+ self._validate_uuid(params.get("user_id"))
172
182
  return await self._request(
173
183
  "GET",
174
184
  f"admin/users/{params.get('user_id')}/factors",
@@ -179,8 +189,14 @@ class AsyncGoTrueAdminAPI(AsyncGoTrueBaseAPI):
179
189
  self,
180
190
  params: AuthMFAAdminDeleteFactorParams,
181
191
  ) -> AuthMFAAdminDeleteFactorResponse:
192
+ self._validate_uuid(params.get("user_id"))
193
+ self._validate_uuid(params.get("id"))
182
194
  return await self._request(
183
195
  "DELETE",
184
- f"admin/users/{params.get('user_id')}/factors/{params.get('factor_id')}",
196
+ f"admin/users/{params.get('user_id')}/factors/{params.get('id')}",
185
197
  xform=partial(model_validate, AuthMFAAdminDeleteFactorResponse),
186
198
  )
199
+
200
+ def _validate_uuid(self, id: str) -> None:
201
+ if not is_valid_uuid(id):
202
+ raise ValueError(f"Invalid id, '{id}' is not a valid uuid")
@@ -79,6 +79,7 @@ from ..types import (
79
79
  SignOutOptions,
80
80
  SignUpWithPasswordCredentials,
81
81
  Subscription,
82
+ UpdateUserOptions,
82
83
  UserAttributes,
83
84
  UserIdentity,
84
85
  UserResponse,
@@ -647,7 +648,9 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
647
648
  return None
648
649
  return await self._request("GET", "user", jwt=jwt, xform=parse_user_response)
649
650
 
650
- async def update_user(self, attributes: UserAttributes) -> UserResponse:
651
+ async def update_user(
652
+ self, attributes: UserAttributes, options: UpdateUserOptions = {}
653
+ ) -> UserResponse:
651
654
  """
652
655
  Updates user data, if there is a logged in user.
653
656
  """
@@ -658,6 +661,7 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
658
661
  "PUT",
659
662
  "user",
660
663
  body=attributes,
664
+ redirect_to=options.get("email_redirect_to"),
661
665
  jwt=session.access_token,
662
666
  xform=parse_user_response,
663
667
  )
@@ -805,14 +809,14 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
805
809
  raise AuthSessionMissingError()
806
810
 
807
811
  body = {
808
- "friendly_name": params["friendly_name"],
809
- "factor_type": params["factor_type"],
812
+ "friendly_name": params.get("friendly_name"),
813
+ "factor_type": params.get("factor_type"),
810
814
  }
811
815
 
812
816
  if params["factor_type"] == "phone":
813
- body["phone"] = params["phone"]
817
+ body["phone"] = params.get("phone")
814
818
  else:
815
- body["issuer"] = params["issuer"]
819
+ body["issuer"] = params.get("issuer")
816
820
 
817
821
  response = await self._request(
818
822
  "POST",
@@ -3,7 +3,12 @@ from __future__ import annotations
3
3
  from functools import partial
4
4
  from typing import Dict, List, Optional
5
5
 
6
- from ..helpers import model_validate, parse_link_response, parse_user_response
6
+ from ..helpers import (
7
+ is_valid_uuid,
8
+ model_validate,
9
+ parse_link_response,
10
+ parse_user_response,
11
+ )
7
12
  from ..http_clients import SyncClient
8
13
  from ..types import (
9
14
  AdminUserAttributes,
@@ -131,6 +136,8 @@ class SyncGoTrueAdminAPI(SyncGoTrueBaseAPI):
131
136
  This function should only be called on a server.
132
137
  Never expose your `service_role` key in the browser.
133
138
  """
139
+ self._validate_uuid(uid)
140
+
134
141
  return self._request(
135
142
  "GET",
136
143
  f"admin/users/{uid}",
@@ -148,6 +155,7 @@ class SyncGoTrueAdminAPI(SyncGoTrueBaseAPI):
148
155
  This function should only be called on a server.
149
156
  Never expose your `service_role` key in the browser.
150
157
  """
158
+ self._validate_uuid(uid)
151
159
  return self._request(
152
160
  "PUT",
153
161
  f"admin/users/{uid}",
@@ -162,6 +170,7 @@ class SyncGoTrueAdminAPI(SyncGoTrueBaseAPI):
162
170
  This function should only be called on a server.
163
171
  Never expose your `service_role` key in the browser.
164
172
  """
173
+ self._validate_uuid(id)
165
174
  body = {"should_soft_delete": should_soft_delete}
166
175
  return self._request("DELETE", f"admin/users/{id}", body=body)
167
176
 
@@ -169,6 +178,7 @@ class SyncGoTrueAdminAPI(SyncGoTrueBaseAPI):
169
178
  self,
170
179
  params: AuthMFAAdminListFactorsParams,
171
180
  ) -> AuthMFAAdminListFactorsResponse:
181
+ self._validate_uuid(params.get("user_id"))
172
182
  return self._request(
173
183
  "GET",
174
184
  f"admin/users/{params.get('user_id')}/factors",
@@ -179,8 +189,14 @@ class SyncGoTrueAdminAPI(SyncGoTrueBaseAPI):
179
189
  self,
180
190
  params: AuthMFAAdminDeleteFactorParams,
181
191
  ) -> AuthMFAAdminDeleteFactorResponse:
192
+ self._validate_uuid(params.get("user_id"))
193
+ self._validate_uuid(params.get("id"))
182
194
  return self._request(
183
195
  "DELETE",
184
- f"admin/users/{params.get('user_id')}/factors/{params.get('factor_id')}",
196
+ f"admin/users/{params.get('user_id')}/factors/{params.get('id')}",
185
197
  xform=partial(model_validate, AuthMFAAdminDeleteFactorResponse),
186
198
  )
199
+
200
+ def _validate_uuid(self, id: str) -> None:
201
+ if not is_valid_uuid(id):
202
+ raise ValueError(f"Invalid id, '{id}' is not a valid uuid")
@@ -79,6 +79,7 @@ from ..types import (
79
79
  SignOutOptions,
80
80
  SignUpWithPasswordCredentials,
81
81
  Subscription,
82
+ UpdateUserOptions,
82
83
  UserAttributes,
83
84
  UserIdentity,
84
85
  UserResponse,
@@ -645,7 +646,9 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
645
646
  return None
646
647
  return self._request("GET", "user", jwt=jwt, xform=parse_user_response)
647
648
 
648
- def update_user(self, attributes: UserAttributes) -> UserResponse:
649
+ def update_user(
650
+ self, attributes: UserAttributes, options: UpdateUserOptions = {}
651
+ ) -> UserResponse:
649
652
  """
650
653
  Updates user data, if there is a logged in user.
651
654
  """
@@ -656,6 +659,7 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
656
659
  "PUT",
657
660
  "user",
658
661
  body=attributes,
662
+ redirect_to=options.get("email_redirect_to"),
659
663
  jwt=session.access_token,
660
664
  xform=parse_user_response,
661
665
  )
@@ -801,14 +805,14 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
801
805
  raise AuthSessionMissingError()
802
806
 
803
807
  body = {
804
- "friendly_name": params["friendly_name"],
805
- "factor_type": params["factor_type"],
808
+ "friendly_name": params.get("friendly_name"),
809
+ "factor_type": params.get("factor_type"),
806
810
  }
807
811
 
808
812
  if params["factor_type"] == "phone":
809
- body["phone"] = params["phone"]
813
+ body["phone"] = params.get("phone")
810
814
  else:
811
- body["issuer"] = params["issuer"]
815
+ body["issuer"] = params.get("issuer")
812
816
 
813
817
  response = self._request(
814
818
  "POST",
@@ -5,6 +5,7 @@ import hashlib
5
5
  import re
6
6
  import secrets
7
7
  import string
8
+ import uuid
8
9
  from base64 import urlsafe_b64decode
9
10
  from datetime import datetime
10
11
  from json import loads
@@ -287,29 +288,6 @@ def is_http_url(url: str) -> bool:
287
288
  return urlparse(url).scheme in {"https", "http"}
288
289
 
289
290
 
290
- def is_valid_jwt(value: str) -> bool:
291
- """Checks if value looks like a JWT, does not do any extra parsing."""
292
- if not isinstance(value, str):
293
- return False
294
-
295
- # Remove trailing whitespaces if any.
296
- value = value.strip()
297
-
298
- # Remove "Bearer " prefix if any.
299
- if value.startswith("Bearer "):
300
- value = value[7:]
301
-
302
- # Valid JWT must have 2 dots (Header.Paylod.Signature)
303
- if value.count(".") != 2:
304
- return False
305
-
306
- for part in value.split("."):
307
- if not re.search(BASE64URL_REGEX, part, re.IGNORECASE):
308
- return False
309
-
310
- return True
311
-
312
-
313
291
  def validate_exp(exp: int) -> None:
314
292
  if not exp:
315
293
  raise AuthInvalidJwtError("JWT has no expiration time")
@@ -317,3 +295,11 @@ def validate_exp(exp: int) -> None:
317
295
  time_now = datetime.now().timestamp()
318
296
  if exp <= time_now:
319
297
  raise AuthInvalidJwtError("JWT has expired")
298
+
299
+
300
+ def is_valid_uuid(value: str) -> bool:
301
+ try:
302
+ uuid.UUID(value)
303
+ return True
304
+ except ValueError:
305
+ return False
File without changes
@@ -4,7 +4,7 @@ from datetime import datetime
4
4
  from time import time
5
5
  from typing import Any, Callable, Dict, List, Optional, Union
6
6
 
7
- from pydantic import BaseModel, ConfigDict
7
+ from pydantic import BaseModel, ConfigDict, Field
8
8
 
9
9
  try:
10
10
  # > 2
@@ -87,6 +87,10 @@ class Options(TypedDict):
87
87
  captcha_token: NotRequired[str]
88
88
 
89
89
 
90
+ class UpdateUserOptions(TypedDict):
91
+ email_redirect_to: NotRequired[str]
92
+
93
+
90
94
  class InviteUserByEmailOptions(TypedDict):
91
95
  redirect_to: NotRequired[str]
92
96
  data: NotRequired[Any]
@@ -229,6 +233,7 @@ class UserAttributes(TypedDict):
229
233
  phone: NotRequired[str]
230
234
  password: NotRequired[str]
231
235
  data: NotRequired[Any]
236
+ nonce: NotRequired[str]
232
237
 
233
238
 
234
239
  class AdminUserAttributes(UserAttributes, TypedDict):
@@ -643,7 +648,7 @@ class AuthMFAEnrollResponse(BaseModel):
643
648
  """
644
649
  Type of MFA factor. Only `totp` supported for now.
645
650
  """
646
- totp: AuthMFAEnrollResponseTotp
651
+ totp: Optional[AuthMFAEnrollResponseTotp] = None
647
652
  """
648
653
  TOTP enrollment information.
649
654
  """
@@ -680,7 +685,9 @@ class AuthMFAChallengeResponse(BaseModel):
680
685
  """
681
686
  Timestamp in UNIX seconds when this challenge will no longer be usable.
682
687
  """
683
- factor_type: Optional[Literal["totp", "phone"]] = None
688
+ factor_type: Optional[Literal["totp", "phone"]] = Field(
689
+ validation_alias="type", default=None
690
+ )
684
691
  """
685
692
  Factor Type which generated the challenge
686
693
  """
@@ -0,0 +1 @@
1
+ __version__ = "2.12.3" # {x-release-please-version}
@@ -1,98 +0,0 @@
1
- # Auth-py
2
-
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?label=license)](https://opensource.org/licenses/MIT)
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)
5
- [![Python](https://img.shields.io/pypi/pyversions/gotrue)](https://pypi.org/project/gotrue)
6
- [![Version](https://img.shields.io/pypi/v/gotrue?color=%2334D058)](https://pypi.org/project/gotrue)
7
- [![Codecov](https://codecov.io/gh/supabase-community/gotrue-py/branch/main/graph/badge.svg)](https://codecov.io/gh/supabase-community/gotrue-py)
8
- [![Last commit](https://img.shields.io/github/last-commit/supabase-community/gotrue-py.svg?style=flat)](https://github.com/supabase-community/gotrue-py/commits)
9
- [![GitHub commit activity](https://img.shields.io/github/commit-activity/m/supabase-community/gotrue-py)](https://github.com/supabase-community/gotrue-py/commits)
10
- [![Github Stars](https://img.shields.io/github/stars/supabase-community/gotrue-py?style=flat&logo=github)](https://github.com/supabase-community/gotrue-py/stargazers)
11
- [![Github Forks](https://img.shields.io/github/forks/supabase-community/gotrue-py?style=flat&logo=github)](https://github.com/supabase-community/gotrue-py/network/members)
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
- [![GitHub contributors](https://img.shields.io/github/contributors/supabase-community/gotrue-py)](https://github.com/supabase-community/gotrue-py/graphs/contributors)
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**. As of December 14th, we renamed to repo from `gotrue-py` to `auth-py` to mirror the changes in the JavaScript library.
16
-
17
- ## Installation
18
-
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
-
21
- ### Poetry
22
-
23
- ```bash
24
- poetry add supabase_auth
25
- ```
26
-
27
- ### Pip
28
-
29
- ```bash
30
- pip install supabase_auth
31
- ```
32
-
33
- ## Differences to the JS client
34
-
35
- It should be noted there are differences to the [JS client](https://github.com/supabase/gotrue-js). If you feel particulaly strongly about them and want to motivate a change, feel free to make a GitHub issue and we can discuss it there.
36
-
37
- Firstly, feature pairity is not 100% with the [JS client](https://github.com/supabase/gotrue-js). In most cases we match the methods and attributes of the [JS client](https://github.com/supabase/gotrue-js) and api classes, but is some places (e.g for browser specific code) it didn't make sense to port the code line for line.
38
-
39
- There is also a divergence in terms of how errors are raised. In the [JS client](https://github.com/supabase/gotrue-js), the errors are returned as part of the object, which the user can choose to process in whatever way they see fit. In this Python client, we raise the errors directly where they originate, as it was felt this was more Pythonic and adhered to the idioms of the language more directly.
40
-
41
- In JS we return the error, but in Python we just raise it.
42
-
43
- ```js
44
- const { data, error } = client.sign_up(...)
45
- ```
46
-
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
-
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
-
51
- ## Usage (outdated)
52
-
53
- **Important:** This section is outdated, you can be guided by the [JS client documentation](https://supabase.github.io/gotrue-js) because this Python client has a lot of parity with the JS client.
54
-
55
- To instantiate the client, you'll need the URL and any request headers at a minimum.
56
-
57
- ```python
58
- from supabase_auth import SyncGoTrueClient
59
-
60
- headers = {
61
- "apiKey": "my-mega-awesome-api-key",
62
- # ... any other headers you might need.
63
- }
64
- client: SyncGoTrueClient = SyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)
65
- ```
66
-
67
- To send a magic email link to the user, just provide the email kwarg to the `sign_in` method:
68
-
69
- ```python
70
- user: Dict[str, Any] = client.sign_up(email="example@gmail.com")
71
- ```
72
-
73
- To login with email and password, provide both to the `sign_in` method:
74
-
75
- ```python
76
- user: Dict[str, Any] = client.sign_up(email="example@gmail.com", password="*********")
77
- ```
78
-
79
- To sign out of the logged in user, call the `sign_out` method. We can then assert that the session and user are null values.
80
-
81
- ```python
82
- client.sign_out()
83
- assert client.user() is None
84
- assert client.session() is None
85
- ```
86
-
87
- We can refesh a users session.
88
-
89
- ```python
90
- # The user should already be signed in at this stage.
91
- user = client.refresh_session()
92
- assert client.user() is not None
93
- assert client.session() is not None
94
- ```
95
-
96
- ## Contributions
97
-
98
- We would be immensely grateful for any contributions to this project.
@@ -1 +0,0 @@
1
- __version__ = "2.12.0" # {x-release-please-version}
File without changes