supabase_auth 0.1.0__py3-none-any.whl
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.
- supabase_auth/__init__.py +13 -0
- supabase_auth/_async/__init__.py +1 -0
- supabase_auth/_async/gotrue_admin_api.py +180 -0
- supabase_auth/_async/gotrue_admin_mfa_api.py +32 -0
- supabase_auth/_async/gotrue_base_api.py +118 -0
- supabase_auth/_async/gotrue_client.py +895 -0
- supabase_auth/_async/gotrue_mfa_api.py +94 -0
- supabase_auth/_async/storage.py +34 -0
- supabase_auth/_sync/__init__.py +1 -0
- supabase_auth/_sync/api.py +649 -0
- supabase_auth/_sync/client.py +641 -0
- supabase_auth/_sync/gotrue_admin_api.py +180 -0
- supabase_auth/_sync/gotrue_admin_mfa_api.py +32 -0
- supabase_auth/_sync/gotrue_base_api.py +118 -0
- supabase_auth/_sync/gotrue_client.py +891 -0
- supabase_auth/_sync/gotrue_mfa_api.py +94 -0
- supabase_auth/_sync/storage.py +34 -0
- supabase_auth/constants.py +14 -0
- supabase_auth/errors.py +115 -0
- supabase_auth/helpers.py +150 -0
- supabase_auth/http_clients.py +9 -0
- supabase_auth/timer.py +44 -0
- supabase_auth/types.py +686 -0
- supabase_auth-0.1.0.dist-info/LICENSE +21 -0
- supabase_auth-0.1.0.dist-info/METADATA +121 -0
- supabase_auth-0.1.0.dist-info/RECORD +27 -0
- supabase_auth-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
__version__ = "2.1.0"
|
|
4
|
+
|
|
5
|
+
from ._async.gotrue_admin_api import AsyncGoTrueAdminAPI # type: ignore # noqa: F401
|
|
6
|
+
from ._async.gotrue_client import AsyncGoTrueClient # type: ignore # noqa: F401
|
|
7
|
+
from ._async.storage import AsyncMemoryStorage # type: ignore # noqa: F401
|
|
8
|
+
from ._async.storage import AsyncSupportedStorage # type: ignore # noqa: F401
|
|
9
|
+
from ._sync.gotrue_admin_api import SyncGoTrueAdminAPI # type: ignore # noqa: F401
|
|
10
|
+
from ._sync.gotrue_client import SyncGoTrueClient # type: ignore # noqa: F401
|
|
11
|
+
from ._sync.storage import SyncMemoryStorage # type: ignore # noqa: F401
|
|
12
|
+
from ._sync.storage import SyncSupportedStorage # type: ignore # noqa: F401
|
|
13
|
+
from .types import * # type: ignore # noqa: F401, F403
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from functools import partial
|
|
4
|
+
from typing import Dict, List, Union
|
|
5
|
+
|
|
6
|
+
from ..helpers import model_validate, parse_link_response, parse_user_response
|
|
7
|
+
from ..http_clients import AsyncClient
|
|
8
|
+
from ..types import (
|
|
9
|
+
AdminUserAttributes,
|
|
10
|
+
AuthMFAAdminDeleteFactorParams,
|
|
11
|
+
AuthMFAAdminDeleteFactorResponse,
|
|
12
|
+
AuthMFAAdminListFactorsParams,
|
|
13
|
+
AuthMFAAdminListFactorsResponse,
|
|
14
|
+
GenerateLinkParams,
|
|
15
|
+
GenerateLinkResponse,
|
|
16
|
+
Options,
|
|
17
|
+
SignOutScope,
|
|
18
|
+
User,
|
|
19
|
+
UserResponse,
|
|
20
|
+
)
|
|
21
|
+
from .gotrue_admin_mfa_api import AsyncGoTrueAdminMFAAPI
|
|
22
|
+
from .gotrue_base_api import AsyncGoTrueBaseAPI
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class AsyncGoTrueAdminAPI(AsyncGoTrueBaseAPI):
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
*,
|
|
29
|
+
url: str = "",
|
|
30
|
+
headers: Dict[str, str] = {},
|
|
31
|
+
http_client: Union[AsyncClient, None] = None,
|
|
32
|
+
) -> None:
|
|
33
|
+
AsyncGoTrueBaseAPI.__init__(
|
|
34
|
+
self,
|
|
35
|
+
url=url,
|
|
36
|
+
headers=headers,
|
|
37
|
+
http_client=http_client,
|
|
38
|
+
)
|
|
39
|
+
self.mfa = AsyncGoTrueAdminMFAAPI()
|
|
40
|
+
self.mfa.list_factors = self._list_factors
|
|
41
|
+
self.mfa.delete_factor = self._delete_factor
|
|
42
|
+
|
|
43
|
+
async def sign_out(self, jwt: str, scope: SignOutScope = "global") -> None:
|
|
44
|
+
"""
|
|
45
|
+
Removes a logged-in session.
|
|
46
|
+
"""
|
|
47
|
+
return await self._request(
|
|
48
|
+
"POST",
|
|
49
|
+
"logout",
|
|
50
|
+
query={"scope": scope},
|
|
51
|
+
jwt=jwt,
|
|
52
|
+
no_resolve_json=True,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
async def invite_user_by_email(
|
|
56
|
+
self,
|
|
57
|
+
email: str,
|
|
58
|
+
options: Options = {},
|
|
59
|
+
) -> UserResponse:
|
|
60
|
+
"""
|
|
61
|
+
Sends an invite link to an email address.
|
|
62
|
+
"""
|
|
63
|
+
return await self._request(
|
|
64
|
+
"POST",
|
|
65
|
+
"invite",
|
|
66
|
+
body={"email": email, "data": options.get("data")},
|
|
67
|
+
redirect_to=options.get("redirect_to"),
|
|
68
|
+
xform=parse_user_response,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
async def generate_link(self, params: GenerateLinkParams) -> GenerateLinkResponse:
|
|
72
|
+
"""
|
|
73
|
+
Generates email links and OTPs to be sent via a custom email provider.
|
|
74
|
+
"""
|
|
75
|
+
return await self._request(
|
|
76
|
+
"POST",
|
|
77
|
+
"admin/generate_link",
|
|
78
|
+
body={
|
|
79
|
+
"type": params.get("type"),
|
|
80
|
+
"email": params.get("email"),
|
|
81
|
+
"password": params.get("password"),
|
|
82
|
+
"new_email": params.get("new_email"),
|
|
83
|
+
"data": params.get("options", {}).get("data"),
|
|
84
|
+
},
|
|
85
|
+
redirect_to=params.get("options", {}).get("redirect_to"),
|
|
86
|
+
xform=parse_link_response,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# User Admin API
|
|
90
|
+
|
|
91
|
+
async def create_user(self, attributes: AdminUserAttributes) -> UserResponse:
|
|
92
|
+
"""
|
|
93
|
+
Creates a new user.
|
|
94
|
+
|
|
95
|
+
This function should only be called on a server.
|
|
96
|
+
Never expose your `service_role` key in the browser.
|
|
97
|
+
"""
|
|
98
|
+
return await self._request(
|
|
99
|
+
"POST",
|
|
100
|
+
"admin/users",
|
|
101
|
+
body=attributes,
|
|
102
|
+
xform=parse_user_response,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
async def list_users(self, page: int = None, per_page: int = None) -> List[User]:
|
|
106
|
+
"""
|
|
107
|
+
Get a list of users.
|
|
108
|
+
|
|
109
|
+
This function should only be called on a server.
|
|
110
|
+
Never expose your `service_role` key in the browser.
|
|
111
|
+
"""
|
|
112
|
+
return await self._request(
|
|
113
|
+
"GET",
|
|
114
|
+
"admin/users",
|
|
115
|
+
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 [],
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
async def get_user_by_id(self, uid: str) -> UserResponse:
|
|
122
|
+
"""
|
|
123
|
+
Get user by id.
|
|
124
|
+
|
|
125
|
+
This function should only be called on a server.
|
|
126
|
+
Never expose your `service_role` key in the browser.
|
|
127
|
+
"""
|
|
128
|
+
return await self._request(
|
|
129
|
+
"GET",
|
|
130
|
+
f"admin/users/{uid}",
|
|
131
|
+
xform=parse_user_response,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
async def update_user_by_id(
|
|
135
|
+
self,
|
|
136
|
+
uid: str,
|
|
137
|
+
attributes: AdminUserAttributes,
|
|
138
|
+
) -> UserResponse:
|
|
139
|
+
"""
|
|
140
|
+
Updates the user data.
|
|
141
|
+
|
|
142
|
+
This function should only be called on a server.
|
|
143
|
+
Never expose your `service_role` key in the browser.
|
|
144
|
+
"""
|
|
145
|
+
return await self._request(
|
|
146
|
+
"PUT",
|
|
147
|
+
f"admin/users/{uid}",
|
|
148
|
+
body=attributes,
|
|
149
|
+
xform=parse_user_response,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
async def delete_user(self, id: str, should_soft_delete: bool = False) -> None:
|
|
153
|
+
"""
|
|
154
|
+
Delete a user. Requires a `service_role` key.
|
|
155
|
+
|
|
156
|
+
This function should only be called on a server.
|
|
157
|
+
Never expose your `service_role` key in the browser.
|
|
158
|
+
"""
|
|
159
|
+
body = {"should_soft_delete": should_soft_delete}
|
|
160
|
+
return await self._request("DELETE", f"admin/users/{id}", body=body)
|
|
161
|
+
|
|
162
|
+
async def _list_factors(
|
|
163
|
+
self,
|
|
164
|
+
params: AuthMFAAdminListFactorsParams,
|
|
165
|
+
) -> AuthMFAAdminListFactorsResponse:
|
|
166
|
+
return await self._request(
|
|
167
|
+
"GET",
|
|
168
|
+
f"admin/users/{params.get('user_id')}/factors",
|
|
169
|
+
xform=partial(model_validate, AuthMFAAdminListFactorsResponse),
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
async def _delete_factor(
|
|
173
|
+
self,
|
|
174
|
+
params: AuthMFAAdminDeleteFactorParams,
|
|
175
|
+
) -> AuthMFAAdminDeleteFactorResponse:
|
|
176
|
+
return await self._request(
|
|
177
|
+
"DELETE",
|
|
178
|
+
f"admin/users/{params.get('user_id')}/factors/{params.get('factor_id')}",
|
|
179
|
+
xform=partial(model_validate, AuthMFAAdminDeleteFactorResponse),
|
|
180
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from ..types import (
|
|
2
|
+
AuthMFAAdminDeleteFactorParams,
|
|
3
|
+
AuthMFAAdminDeleteFactorResponse,
|
|
4
|
+
AuthMFAAdminListFactorsParams,
|
|
5
|
+
AuthMFAAdminListFactorsResponse,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AsyncGoTrueAdminMFAAPI:
|
|
10
|
+
"""
|
|
11
|
+
Contains the full multi-factor authentication administration API.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
async def list_factors(
|
|
15
|
+
self,
|
|
16
|
+
params: AuthMFAAdminListFactorsParams,
|
|
17
|
+
) -> AuthMFAAdminListFactorsResponse:
|
|
18
|
+
"""
|
|
19
|
+
Lists all factors attached to a user.
|
|
20
|
+
"""
|
|
21
|
+
raise NotImplementedError() # pragma: no cover
|
|
22
|
+
|
|
23
|
+
async def delete_factor(
|
|
24
|
+
self,
|
|
25
|
+
params: AuthMFAAdminDeleteFactorParams,
|
|
26
|
+
) -> AuthMFAAdminDeleteFactorResponse:
|
|
27
|
+
"""
|
|
28
|
+
Deletes a factor on a user. This will log the user out of all active
|
|
29
|
+
sessions (if the deleted factor was verified). There's no need to delete
|
|
30
|
+
unverified factors.
|
|
31
|
+
"""
|
|
32
|
+
raise NotImplementedError() # pragma: no cover
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Callable, Dict, TypeVar, Union, overload
|
|
4
|
+
|
|
5
|
+
from httpx import Response
|
|
6
|
+
from pydantic import BaseModel
|
|
7
|
+
from typing_extensions import Literal, Self
|
|
8
|
+
|
|
9
|
+
from ..helpers import handle_exception, model_dump
|
|
10
|
+
from ..http_clients import AsyncClient
|
|
11
|
+
|
|
12
|
+
T = TypeVar("T")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AsyncGoTrueBaseAPI:
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
*,
|
|
19
|
+
url: str,
|
|
20
|
+
headers: Dict[str, str],
|
|
21
|
+
http_client: Union[AsyncClient, None],
|
|
22
|
+
):
|
|
23
|
+
self._url = url
|
|
24
|
+
self._headers = headers
|
|
25
|
+
self._http_client = http_client or AsyncClient()
|
|
26
|
+
|
|
27
|
+
async def __aenter__(self) -> Self:
|
|
28
|
+
return self
|
|
29
|
+
|
|
30
|
+
async def __aexit__(self, exc_t, exc_v, exc_tb) -> None:
|
|
31
|
+
await self.close()
|
|
32
|
+
|
|
33
|
+
async def close(self) -> None:
|
|
34
|
+
await self._http_client.aclose()
|
|
35
|
+
|
|
36
|
+
@overload
|
|
37
|
+
async def _request(
|
|
38
|
+
self,
|
|
39
|
+
method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"],
|
|
40
|
+
path: str,
|
|
41
|
+
*,
|
|
42
|
+
jwt: Union[str, None] = None,
|
|
43
|
+
redirect_to: Union[str, None] = None,
|
|
44
|
+
headers: Union[Dict[str, str], None] = None,
|
|
45
|
+
query: Union[Dict[str, str], None] = None,
|
|
46
|
+
body: Union[Any, None] = None,
|
|
47
|
+
no_resolve_json: Literal[False] = False,
|
|
48
|
+
xform: Callable[[Any], T],
|
|
49
|
+
) -> T:
|
|
50
|
+
... # pragma: no cover
|
|
51
|
+
|
|
52
|
+
@overload
|
|
53
|
+
async def _request(
|
|
54
|
+
self,
|
|
55
|
+
method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"],
|
|
56
|
+
path: str,
|
|
57
|
+
*,
|
|
58
|
+
jwt: Union[str, None] = None,
|
|
59
|
+
redirect_to: Union[str, None] = None,
|
|
60
|
+
headers: Union[Dict[str, str], None] = None,
|
|
61
|
+
query: Union[Dict[str, str], None] = None,
|
|
62
|
+
body: Union[Any, None] = None,
|
|
63
|
+
no_resolve_json: Literal[True],
|
|
64
|
+
xform: Callable[[Response], T],
|
|
65
|
+
) -> T:
|
|
66
|
+
... # pragma: no cover
|
|
67
|
+
|
|
68
|
+
@overload
|
|
69
|
+
async def _request(
|
|
70
|
+
self,
|
|
71
|
+
method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"],
|
|
72
|
+
path: str,
|
|
73
|
+
*,
|
|
74
|
+
jwt: Union[str, None] = None,
|
|
75
|
+
redirect_to: Union[str, None] = None,
|
|
76
|
+
headers: Union[Dict[str, str], None] = None,
|
|
77
|
+
query: Union[Dict[str, str], None] = None,
|
|
78
|
+
body: Union[Any, None] = None,
|
|
79
|
+
no_resolve_json: bool = False,
|
|
80
|
+
) -> None:
|
|
81
|
+
... # pragma: no cover
|
|
82
|
+
|
|
83
|
+
async def _request(
|
|
84
|
+
self,
|
|
85
|
+
method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"],
|
|
86
|
+
path: str,
|
|
87
|
+
*,
|
|
88
|
+
jwt: Union[str, None] = None,
|
|
89
|
+
redirect_to: Union[str, None] = None,
|
|
90
|
+
headers: Union[Dict[str, str], None] = None,
|
|
91
|
+
query: Union[Dict[str, str], None] = None,
|
|
92
|
+
body: Union[Any, None] = None,
|
|
93
|
+
no_resolve_json: bool = False,
|
|
94
|
+
xform: Union[Callable[[Any], T], None] = None,
|
|
95
|
+
) -> Union[T, None]:
|
|
96
|
+
url = f"{self._url}/{path}"
|
|
97
|
+
headers = {**self._headers, **(headers or {})}
|
|
98
|
+
if "Content-Type" not in headers:
|
|
99
|
+
headers["Content-Type"] = "application/json;charset=UTF-8"
|
|
100
|
+
if jwt:
|
|
101
|
+
headers["Authorization"] = f"Bearer {jwt}"
|
|
102
|
+
query = query or {}
|
|
103
|
+
if redirect_to:
|
|
104
|
+
query["redirect_to"] = redirect_to
|
|
105
|
+
try:
|
|
106
|
+
response = await self._http_client.request(
|
|
107
|
+
method,
|
|
108
|
+
url,
|
|
109
|
+
headers=headers,
|
|
110
|
+
params=query,
|
|
111
|
+
json=model_dump(body) if isinstance(body, BaseModel) else body,
|
|
112
|
+
)
|
|
113
|
+
response.raise_for_status()
|
|
114
|
+
result = response if no_resolve_json else response.json()
|
|
115
|
+
if xform:
|
|
116
|
+
return xform(result)
|
|
117
|
+
except Exception as e:
|
|
118
|
+
raise handle_exception(e)
|