apexauthlib 0.1.4__py3-none-any.whl → 0.1.5__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.
- apexauthlib/entities/auth.py +10 -1
- apexauthlib/fastapi/auth.py +16 -0
- apexauthlib/integration/api.py +27 -4
- {apexauthlib-0.1.4.dist-info → apexauthlib-0.1.5.dist-info}/METADATA +1 -1
- apexauthlib-0.1.5.dist-info/RECORD +11 -0
- {apexauthlib-0.1.4.dist-info → apexauthlib-0.1.5.dist-info}/WHEEL +1 -1
- apexauthlib-0.1.4.dist-info/RECORD +0 -11
- {apexauthlib-0.1.4.dist-info → apexauthlib-0.1.5.dist-info}/LICENSE +0 -0
apexauthlib/entities/auth.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
from dataclasses import dataclass, field
|
|
2
|
-
from typing import Any
|
|
2
|
+
from typing import Any, Generic, TypeVar
|
|
3
3
|
from uuid import uuid4
|
|
4
4
|
|
|
5
|
+
ItemT = TypeVar("ItemT")
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
@dataclass(frozen=True)
|
|
7
9
|
class User:
|
|
@@ -39,3 +41,10 @@ class UserMetadata:
|
|
|
39
41
|
class Client:
|
|
40
42
|
client_id: str
|
|
41
43
|
hashed_secret: str
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class ServiceUserInfo(Generic[ItemT]):
|
|
48
|
+
user: User
|
|
49
|
+
is_superuser: bool
|
|
50
|
+
metadata: ItemT
|
apexauthlib/fastapi/auth.py
CHANGED
|
@@ -7,6 +7,7 @@ from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
|
|
7
7
|
from starlette import status
|
|
8
8
|
|
|
9
9
|
from apexauthlib.entities import User
|
|
10
|
+
from apexauthlib.entities.auth import ServiceUserInfo
|
|
10
11
|
from apexauthlib.integration.api import AuthApiProvider, AuthCodeApi
|
|
11
12
|
|
|
12
13
|
auth_api = APIRouter(tags=["Auth"])
|
|
@@ -67,6 +68,21 @@ def get_user_with_metadata(
|
|
|
67
68
|
)
|
|
68
69
|
|
|
69
70
|
|
|
71
|
+
def get_user_with_full_metadata(
|
|
72
|
+
token: TokenDependable,
|
|
73
|
+
auth: AuthApiProviderDependable,
|
|
74
|
+
) -> ServiceUserInfo[Any]:
|
|
75
|
+
try:
|
|
76
|
+
api = auth.for_token(token)
|
|
77
|
+
return api.full_metadata_for(api.user().id)
|
|
78
|
+
except Exception as e:
|
|
79
|
+
raise HTTPException(
|
|
80
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
81
|
+
detail=str(e),
|
|
82
|
+
headers={"WWW-Authenticate": "Bearer"},
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
70
86
|
@dataclass
|
|
71
87
|
class TokenResponse:
|
|
72
88
|
access_token: str
|
apexauthlib/integration/api.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from dataclasses import dataclass
|
|
4
|
-
from typing import Any, Generic, Mapping
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Any, Generic, Mapping
|
|
5
5
|
|
|
6
6
|
from apexdevkit.formatter import DataclassFormatter, Formatter
|
|
7
7
|
from apexdevkit.http import FluentHttp, JsonDict
|
|
8
8
|
|
|
9
9
|
from apexauthlib.entities import User
|
|
10
|
-
|
|
11
|
-
ItemT = TypeVar("ItemT")
|
|
10
|
+
from apexauthlib.entities.auth import ItemT, ServiceUserInfo
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
@dataclass(frozen=True)
|
|
@@ -48,6 +47,10 @@ class AuthApi(Generic[ItemT]):
|
|
|
48
47
|
formatter: Formatter[Mapping[str, Any], ItemT]
|
|
49
48
|
token: str
|
|
50
49
|
|
|
50
|
+
user_formatter: Formatter[Mapping[str, Any], User] = field(
|
|
51
|
+
default_factory=lambda: DataclassFormatter(User)
|
|
52
|
+
)
|
|
53
|
+
|
|
51
54
|
def user(self) -> User:
|
|
52
55
|
return DataclassFormatter(User).load(
|
|
53
56
|
(
|
|
@@ -72,6 +75,26 @@ class AuthApi(Generic[ItemT]):
|
|
|
72
75
|
|
|
73
76
|
return self.formatter.load(JsonDict(result["data"]["metadata"]["metadata"]))
|
|
74
77
|
|
|
78
|
+
def full_metadata_for(self, user_id: str) -> ServiceUserInfo[ItemT]:
|
|
79
|
+
result = JsonDict(
|
|
80
|
+
(
|
|
81
|
+
self.http.with_header("Authorization", f"Bearer {self.token}")
|
|
82
|
+
.get()
|
|
83
|
+
.on_endpoint(f"/services/{self.service_name}/users/{user_id}")
|
|
84
|
+
.on_failure(raises=RuntimeError)
|
|
85
|
+
.json()
|
|
86
|
+
)
|
|
87
|
+
)["data"]["user"]
|
|
88
|
+
|
|
89
|
+
user = dict(result["user"])
|
|
90
|
+
user["hashed_password"] = "unknown"
|
|
91
|
+
|
|
92
|
+
return ServiceUserInfo[ItemT](
|
|
93
|
+
user=self.user_formatter.load(user),
|
|
94
|
+
is_superuser=bool(result["is_superuser"]),
|
|
95
|
+
metadata=self.formatter.load(result["metadata"]),
|
|
96
|
+
)
|
|
97
|
+
|
|
75
98
|
|
|
76
99
|
@dataclass
|
|
77
100
|
class AuthCodeApi:
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
apexauthlib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
apexauthlib/entities/__init__.py,sha256=KghMo6a2QWdPzWlMqdGAKOaVvRmTCOIVhXtIHrX7A_M,149
|
|
3
|
+
apexauthlib/entities/auth.py,sha256=TOs-3eNWodjrI8iFpozsNnn1KQTbPKCllbGzHSPYah8,836
|
|
4
|
+
apexauthlib/fastapi/__init__.py,sha256=G77C3ZIqjsXdh4fiH5FZyF_hyzVtS3waJJGa_TBGMWE,103
|
|
5
|
+
apexauthlib/fastapi/auth.py,sha256=rPQzLSbXEkfjF2PQXvD4XPfGtHVjBKpGuQLNl0-pZCo,3429
|
|
6
|
+
apexauthlib/integration/__init__.py,sha256=f2lGbyoGct4kpZ2CUTExHhtQHs-1YR_xanvrj9Y4GiI,87
|
|
7
|
+
apexauthlib/integration/api.py,sha256=dv32rPikRsOVvIOmived4Z187qB4QK0eWtLxkfWaoTo,3528
|
|
8
|
+
apexauthlib-0.1.5.dist-info/LICENSE,sha256=iai0ILQTDgUXV1cIXl0UzSeOdFpMFK3shn5aqnz_Uro,1065
|
|
9
|
+
apexauthlib-0.1.5.dist-info/METADATA,sha256=bXlGvI7rmq-ZPtXVHpaZ5lLiIqyVgPCLfedBiUhtY_c,518
|
|
10
|
+
apexauthlib-0.1.5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
11
|
+
apexauthlib-0.1.5.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
apexauthlib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
apexauthlib/entities/__init__.py,sha256=KghMo6a2QWdPzWlMqdGAKOaVvRmTCOIVhXtIHrX7A_M,149
|
|
3
|
-
apexauthlib/entities/auth.py,sha256=1v5n8T1HdVt_3PV30wr2R6BdHzKDK90wdiNwEw1GZS8,669
|
|
4
|
-
apexauthlib/fastapi/__init__.py,sha256=G77C3ZIqjsXdh4fiH5FZyF_hyzVtS3waJJGa_TBGMWE,103
|
|
5
|
-
apexauthlib/fastapi/auth.py,sha256=YfQ36sp9ddYKsvsnkqxpR7UVIUPgUz0HMLOrlJ46Ze4,2952
|
|
6
|
-
apexauthlib/integration/__init__.py,sha256=f2lGbyoGct4kpZ2CUTExHhtQHs-1YR_xanvrj9Y4GiI,87
|
|
7
|
-
apexauthlib/integration/api.py,sha256=Q2tUJFilDe2L-OWmCydcY7rHjES2wOk1Wpa8jymV48A,2661
|
|
8
|
-
apexauthlib-0.1.4.dist-info/LICENSE,sha256=iai0ILQTDgUXV1cIXl0UzSeOdFpMFK3shn5aqnz_Uro,1065
|
|
9
|
-
apexauthlib-0.1.4.dist-info/METADATA,sha256=KfTFsvr-Z_Z7Qnp3IZ22ezhjuX0Rq6m9h1-DgtacVYg,518
|
|
10
|
-
apexauthlib-0.1.4.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
11
|
-
apexauthlib-0.1.4.dist-info/RECORD,,
|
|
File without changes
|