apexauthlib 0.1.0__py3-none-any.whl → 0.1.2__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.
@@ -0,0 +1,3 @@
1
+ from apexauthlib.entities.auth import Service, ServiceMetadata, User, UserMetadata
2
+
3
+ __all__ = ["User", "Service", "UserMetadata", "ServiceMetadata"]
@@ -0,0 +1,35 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import Any
3
+ from uuid import uuid4
4
+
5
+
6
+ @dataclass(frozen=True)
7
+ class User:
8
+ username: str
9
+ hashed_password: str
10
+ first_name: str
11
+ last_name: str
12
+ email: str
13
+ phone_number: str
14
+
15
+ is_admin: bool
16
+
17
+ id: str = field(default_factory=lambda: str(uuid4()))
18
+
19
+
20
+ @dataclass(frozen=True)
21
+ class Service:
22
+ service: str
23
+ superuser: str
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class ServiceMetadata:
28
+ user_id: str
29
+ metadata: dict[str, Any]
30
+
31
+
32
+ @dataclass(frozen=True)
33
+ class UserMetadata:
34
+ service: str
35
+ metadata: dict[str, Any]
@@ -6,6 +6,7 @@ from fastapi import APIRouter, Depends, HTTPException
6
6
  from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
7
7
  from starlette import status
8
8
 
9
+ from apexauthlib.entities import User
9
10
  from apexauthlib.integration.api import AuthApiProvider
10
11
 
11
12
  auth_api = APIRouter(tags=["Auth"])
@@ -22,10 +23,41 @@ TokenDependable = Annotated[str, Depends(oauth2())]
22
23
  def get_user(
23
24
  token: TokenDependable,
24
25
  auth: AuthApiProviderDependable,
26
+ ) -> User:
27
+ try:
28
+ api = auth.for_token(token)
29
+ return api.user()
30
+ except Exception as e:
31
+ raise HTTPException(
32
+ status_code=status.HTTP_401_UNAUTHORIZED,
33
+ detail=str(e),
34
+ headers={"WWW-Authenticate": "Bearer"},
35
+ )
36
+
37
+
38
+ def get_user_metadata(
39
+ token: TokenDependable,
40
+ auth: AuthApiProviderDependable,
25
41
  ) -> Any:
26
42
  try:
27
43
  api = auth.for_token(token)
28
- return api.metadata_for(api.user())
44
+ return api.metadata_for(api.user().id)
45
+ except Exception as e:
46
+ raise HTTPException(
47
+ status_code=status.HTTP_401_UNAUTHORIZED,
48
+ detail=str(e),
49
+ headers={"WWW-Authenticate": "Bearer"},
50
+ )
51
+
52
+
53
+ def get_user_with_metadata(
54
+ token: TokenDependable,
55
+ auth: AuthApiProviderDependable,
56
+ ) -> tuple[User, Any]:
57
+ try:
58
+ api = auth.for_token(token)
59
+ user = api.user()
60
+ return user, api.metadata_for(api.user().id)
29
61
  except Exception as e:
30
62
  raise HTTPException(
31
63
  status_code=status.HTTP_401_UNAUTHORIZED,
@@ -3,9 +3,11 @@ from __future__ import annotations
3
3
  from dataclasses import dataclass
4
4
  from typing import Any, Generic, Mapping, TypeVar
5
5
 
6
- from apexdevkit.formatter import Formatter
6
+ from apexdevkit.formatter import DataclassFormatter, Formatter
7
7
  from apexdevkit.http import FluentHttp, JsonDict
8
8
 
9
+ from apexauthlib.entities import User
10
+
9
11
  ItemT = TypeVar("ItemT")
10
12
 
11
13
 
@@ -46,15 +48,15 @@ class AuthApi(Generic[ItemT]):
46
48
  formatter: Formatter[Mapping[str, Any], ItemT]
47
49
  token: str
48
50
 
49
- def user(self) -> str:
50
- return str(
51
+ def user(self) -> User:
52
+ return DataclassFormatter(User).load(
51
53
  (
52
54
  self.http.with_header("Authorization", f"Bearer {self.token}")
53
55
  .get()
54
56
  .on_endpoint("/auth/user")
55
57
  .on_failure(raises=RuntimeError)
56
58
  .json()
57
- )["id"]
59
+ )
58
60
  )
59
61
 
60
62
  def metadata_for(self, user_id: str) -> ItemT:
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.3
2
+ Name: apexauthlib
3
+ Version: 0.1.2
4
+ Summary: Apex authorization library for services
5
+ Author: Apex Dev
6
+ Author-email: dev@apex.ge
7
+ Requires-Python: >=3.12
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Requires-Dist: apexdevkit
12
+ Requires-Dist: fastapi
13
+ Requires-Dist: httpx
14
+ Requires-Dist: uvicorn
15
+ Description-Content-Type: text/markdown
16
+
17
+ # apexauthlib
18
+ Central authorization library for apex services
19
+
@@ -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=ol_s7Y3AtH7PiFvxLP855ujSfdYSOuwA2bebuWDjSxU,587
4
+ apexauthlib/fastapi/__init__.py,sha256=G77C3ZIqjsXdh4fiH5FZyF_hyzVtS3waJJGa_TBGMWE,103
5
+ apexauthlib/fastapi/auth.py,sha256=PQWjGty-nAff3seYJ_HLbtuvhYZ9NZPt83HS6SjhlyA,2419
6
+ apexauthlib/integration/__init__.py,sha256=f2lGbyoGct4kpZ2CUTExHhtQHs-1YR_xanvrj9Y4GiI,87
7
+ apexauthlib/integration/api.py,sha256=98KpcsLoizRCzTr1y_HEK0NVOV6jEeh8aeX8FoB8dTs,2105
8
+ apexauthlib-0.1.2.dist-info/LICENSE,sha256=iai0ILQTDgUXV1cIXl0UzSeOdFpMFK3shn5aqnz_Uro,1065
9
+ apexauthlib-0.1.2.dist-info/METADATA,sha256=uqc9JBXQWRsUFhbdKxXfFw5EybAsnspS4yGRq8Xaolo,518
10
+ apexauthlib-0.1.2.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
11
+ apexauthlib-0.1.2.dist-info/RECORD,,
@@ -1,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: poetry-core 2.1.2
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
@@ -1,12 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: apexauthlib
3
- Version: 0.1.0
4
- Summary: Apex authorization library for services
5
- Author-email: Apex Dev <dev@apex.ge>
6
- Requires-Python: >=3.12
7
- Description-Content-Type: text/markdown
8
- License-File: LICENSE
9
- Dynamic: license-file
10
-
11
- # apexauthlib
12
- Authorization library for apex services
@@ -1,10 +0,0 @@
1
- apexauthlib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- apexauthlib/fastapi/__init__.py,sha256=G77C3ZIqjsXdh4fiH5FZyF_hyzVtS3waJJGa_TBGMWE,103
3
- apexauthlib/fastapi/auth.py,sha256=i8mI0s2FuM-5HXvE_A_tyzlh9miTEwtYYTWhgXsACN8,1566
4
- apexauthlib/integration/__init__.py,sha256=f2lGbyoGct4kpZ2CUTExHhtQHs-1YR_xanvrj9Y4GiI,87
5
- apexauthlib/integration/api.py,sha256=VRsLMPNjFZ6TynLkWnfiCrf4_XOknc71-ReiHvk3jUQ,2025
6
- apexauthlib-0.1.0.dist-info/licenses/LICENSE,sha256=iai0ILQTDgUXV1cIXl0UzSeOdFpMFK3shn5aqnz_Uro,1065
7
- apexauthlib-0.1.0.dist-info/METADATA,sha256=AozfBfuJaKMzG9gKXf5oxJbhGvSA6DCocmBt8Vj_Arc,304
8
- apexauthlib-0.1.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
9
- apexauthlib-0.1.0.dist-info/top_level.txt,sha256=7oTWvKq-w1XF5wjuTA543Wo4erFjvATET8N-HxgBS8Y,12
10
- apexauthlib-0.1.0.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- apexauthlib