supabase_auth 2.12.0__tar.gz → 2.12.2__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.2}/PKG-INFO +92 -31
  2. supabase_auth-2.12.2/README.md +159 -0
  3. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/pyproject.toml +6 -6
  4. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_async/gotrue_admin_api.py +18 -2
  5. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_async/gotrue_client.py +4 -4
  6. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_sync/gotrue_admin_api.py +18 -2
  7. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_sync/gotrue_client.py +4 -4
  8. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/helpers.py +9 -23
  9. supabase_auth-2.12.2/supabase_auth/py.typed +0 -0
  10. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/types.py +5 -3
  11. supabase_auth-2.12.2/supabase_auth/version.py +1 -0
  12. supabase_auth-2.12.0/README.md +0 -98
  13. supabase_auth-2.12.0/supabase_auth/version.py +0 -1
  14. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/LICENSE +0 -0
  15. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/__init__.py +0 -0
  16. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_async/__init__.py +0 -0
  17. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_async/gotrue_admin_mfa_api.py +0 -0
  18. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_async/gotrue_base_api.py +0 -0
  19. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_async/gotrue_mfa_api.py +0 -0
  20. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_async/storage.py +0 -0
  21. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_sync/__init__.py +0 -0
  22. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_sync/gotrue_admin_mfa_api.py +0 -0
  23. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_sync/gotrue_base_api.py +0 -0
  24. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_sync/gotrue_mfa_api.py +0 -0
  25. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/_sync/storage.py +0 -0
  26. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/constants.py +0 -0
  27. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/errors.py +0 -0
  28. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/supabase_auth/http_clients.py +0 -0
  29. {supabase_auth-2.12.0 → supabase_auth-2.12.2}/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.2
4
4
  Summary: Python Client Library for Supabase Auth
5
5
  Home-page: https://github.com/supabase/auth-py
6
6
  License: MIT
@@ -25,23 +25,16 @@ Description-Content-Type: text/markdown
25
25
 
26
26
  # Auth-py
27
27
 
28
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?label=license)](https://opensource.org/licenses/MIT)
29
28
  [![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
29
  [![Python](https://img.shields.io/pypi/pyversions/gotrue)](https://pypi.org/project/gotrue)
31
30
  [![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)
31
+ [![Coverage Status](https://coveralls.io/repos/github/supabase/auth-py/badge.svg?branch=main)](https://coveralls.io/github/supabase/auth-py?branch=main)
39
32
 
40
33
  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
34
 
42
35
  ## Installation
43
36
 
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.
37
+ The package can be installed using pip or poetry:
45
38
 
46
39
  ### Poetry
47
40
 
@@ -55,6 +48,19 @@ poetry add supabase_auth
55
48
  pip install supabase_auth
56
49
  ```
57
50
 
51
+ ## Features
52
+
53
+ - Full feature parity with the JavaScript client
54
+ - Support for both synchronous and asynchronous operations
55
+ - MFA (Multi-Factor Authentication) support
56
+ - OAuth and SSO integration
57
+ - Magic link and OTP authentication
58
+ - Phone number authentication
59
+ - Anonymous sign-in
60
+ - Session management with auto-refresh
61
+ - JWT token handling and verification
62
+ - User management and profile updates
63
+
58
64
  ## Differences to the JS client
59
65
 
60
66
  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 +79,11 @@ The other key difference is we do not use pascalCase to encode variable and meth
73
79
 
74
80
  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
81
 
76
- ## Usage (outdated)
82
+ ## Usage
77
83
 
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.
84
+ The library provides both synchronous and asynchronous clients. Here are some examples:
79
85
 
80
- To instantiate the client, you'll need the URL and any request headers at a minimum.
86
+ ### Synchronous Client
81
87
 
82
88
  ```python
83
89
  from supabase_auth import SyncGoTrueClient
@@ -87,38 +93,93 @@ headers = {
87
93
  # ... any other headers you might need.
88
94
  }
89
95
  client: SyncGoTrueClient = SyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)
90
- ```
91
96
 
92
- To send a magic email link to the user, just provide the email kwarg to the `sign_in` method:
97
+ # Sign up with email and password
98
+ user = client.sign_up(email="example@gmail.com", password="*********")
93
99
 
94
- ```python
95
- user: Dict[str, Any] = client.sign_up(email="example@gmail.com")
96
- ```
100
+ # Sign in with email and password
101
+ user = client.sign_in_with_password(email="example@gmail.com", password="*********")
97
102
 
98
- To login with email and password, provide both to the `sign_in` method:
103
+ # Sign in with magic link
104
+ user = client.sign_in_with_otp(email="example@gmail.com")
99
105
 
100
- ```python
101
- user: Dict[str, Any] = client.sign_up(email="example@gmail.com", password="*********")
106
+ # Sign in with phone number
107
+ user = client.sign_in_with_otp(phone="+1234567890")
108
+
109
+ # Sign in with OAuth
110
+ user = client.sign_in_with_oauth(provider="google")
111
+
112
+ # Sign out
113
+ client.sign_out()
114
+
115
+ # Get current user
116
+ user = client.get_user()
117
+
118
+ # Update user profile
119
+ user = client.update_user({"data": {"name": "John Doe"}})
102
120
  ```
103
121
 
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.
122
+ ### Asynchronous Client
105
123
 
106
124
  ```python
107
- client.sign_out()
108
- assert client.user() is None
109
- assert client.session() is None
125
+ from supabase_auth import AsyncGoTrueClient
126
+
127
+ headers = {
128
+ "apiKey": "my-mega-awesome-api-key",
129
+ # ... any other headers you might need.
130
+ }
131
+ client: AsyncGoTrueClient = AsyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)
132
+
133
+ async def main():
134
+ # Sign up with email and password
135
+ user = await client.sign_up(email="example@gmail.com", password="*********")
136
+
137
+ # Sign in with email and password
138
+ user = await client.sign_in_with_password(email="example@gmail.com", password="*********")
139
+
140
+ # Sign in with magic link
141
+ user = await client.sign_in_with_otp(email="example@gmail.com")
142
+
143
+ # Sign in with phone number
144
+ user = await client.sign_in_with_otp(phone="+1234567890")
145
+
146
+ # Sign in with OAuth
147
+ user = await client.sign_in_with_oauth(provider="google")
148
+
149
+ # Sign out
150
+ await client.sign_out()
151
+
152
+ # Get current user
153
+ user = await client.get_user()
154
+
155
+ # Update user profile
156
+ user = await client.update_user({"data": {"name": "John Doe"}})
157
+
158
+ # Run the async code
159
+ import asyncio
160
+ asyncio.run(main())
110
161
  ```
111
162
 
112
- We can refesh a users session.
163
+ ### MFA Support
164
+
165
+ The library includes support for Multi-Factor Authentication:
113
166
 
114
167
  ```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
168
+ # List MFA factors
169
+ factors = client.mfa.list_factors()
170
+
171
+ # Enroll a new MFA factor
172
+ enrolled_factor = client.mfa.enroll({"factor_type": "totp"})
173
+
174
+ # Challenge and verify MFA
175
+ challenge = client.mfa.challenge({"factor_id": "factor_id"})
176
+ verified = client.mfa.verify({"factor_id": "factor_id", "code": "123456"})
177
+
178
+ # Unenroll a factor
179
+ client.mfa.unenroll({"factor_id": "factor_id"})
119
180
  ```
120
181
 
121
182
  ## Contributions
122
183
 
123
- We would be immensely grateful for any contributions to this project.
184
+ We would be immensely grateful for any contributions to this project.
124
185
 
@@ -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.2" # {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"
@@ -22,15 +22,15 @@ pyjwt = "^2.10.1"
22
22
  pytest-mock = "^3.14.0"
23
23
 
24
24
  [tool.poetry.dev-dependencies]
25
- pytest = "^8.3.5"
26
- flake8 = "^7.1.2"
25
+ pytest = "^8.4.1"
26
+ flake8 = "^7.3.0"
27
27
  black = "^25.1.0"
28
28
  isort = "^6.0.1"
29
29
  pre-commit = "^4.2.0"
30
- pytest-cov = "^6.0.0"
30
+ pytest-cov = "^6.2.1"
31
31
  pytest-depends = "^1.0.1"
32
- pytest-asyncio = "^0.26.0"
33
- Faker = "^37.1.0"
32
+ pytest-asyncio = "^1.0.0"
33
+ Faker = "^37.4.0"
34
34
  unasync-cli = { git = "https://github.com/supabase-community/unasync-cli.git", branch = "main" }
35
35
 
36
36
  [tool.poetry.group.dev.dependencies]
@@ -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")
@@ -805,14 +805,14 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
805
805
  raise AuthSessionMissingError()
806
806
 
807
807
  body = {
808
- "friendly_name": params["friendly_name"],
809
- "factor_type": params["factor_type"],
808
+ "friendly_name": params.get("friendly_name"),
809
+ "factor_type": params.get("factor_type"),
810
810
  }
811
811
 
812
812
  if params["factor_type"] == "phone":
813
- body["phone"] = params["phone"]
813
+ body["phone"] = params.get("phone")
814
814
  else:
815
- body["issuer"] = params["issuer"]
815
+ body["issuer"] = params.get("issuer")
816
816
 
817
817
  response = await self._request(
818
818
  "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")
@@ -801,14 +801,14 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
801
801
  raise AuthSessionMissingError()
802
802
 
803
803
  body = {
804
- "friendly_name": params["friendly_name"],
805
- "factor_type": params["factor_type"],
804
+ "friendly_name": params.get("friendly_name"),
805
+ "factor_type": params.get("factor_type"),
806
806
  }
807
807
 
808
808
  if params["factor_type"] == "phone":
809
- body["phone"] = params["phone"]
809
+ body["phone"] = params.get("phone")
810
810
  else:
811
- body["issuer"] = params["issuer"]
811
+ body["issuer"] = params.get("issuer")
812
812
 
813
813
  response = self._request(
814
814
  "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
@@ -643,7 +643,7 @@ class AuthMFAEnrollResponse(BaseModel):
643
643
  """
644
644
  Type of MFA factor. Only `totp` supported for now.
645
645
  """
646
- totp: AuthMFAEnrollResponseTotp
646
+ totp: Optional[AuthMFAEnrollResponseTotp] = None
647
647
  """
648
648
  TOTP enrollment information.
649
649
  """
@@ -680,7 +680,9 @@ class AuthMFAChallengeResponse(BaseModel):
680
680
  """
681
681
  Timestamp in UNIX seconds when this challenge will no longer be usable.
682
682
  """
683
- factor_type: Optional[Literal["totp", "phone"]] = None
683
+ factor_type: Optional[Literal["totp", "phone"]] = Field(
684
+ validation_alias="type", default=None
685
+ )
684
686
  """
685
687
  Factor Type which generated the challenge
686
688
  """
@@ -0,0 +1 @@
1
+ __version__ = "2.12.2" # {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