apexauthlib 0.1.5__py3-none-any.whl → 0.1.7__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.
@@ -83,6 +83,21 @@ def get_user_with_full_metadata(
83
83
  )
84
84
 
85
85
 
86
+ def get_user_and_service_users(
87
+ token: TokenDependable,
88
+ auth: AuthApiProviderDependable,
89
+ ) -> tuple[ServiceUserInfo[Any], list[ServiceUserInfo[Any]]]:
90
+ try:
91
+ api = auth.for_token(token)
92
+ return api.full_metadata_for(api.user().id), list(api.users_for_service())
93
+ except Exception as e:
94
+ raise HTTPException(
95
+ status_code=status.HTTP_401_UNAUTHORIZED,
96
+ detail=str(e),
97
+ headers={"WWW-Authenticate": "Bearer"},
98
+ )
99
+
100
+
86
101
  @dataclass
87
102
  class TokenResponse:
88
103
  access_token: str
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from dataclasses import dataclass, field
4
- from typing import Any, Generic, Mapping
4
+ from typing import Any, Generic, Iterable, Mapping
5
5
 
6
6
  from apexdevkit.formatter import DataclassFormatter, Formatter
7
7
  from apexdevkit.http import FluentHttp, JsonDict
@@ -95,6 +95,27 @@ class AuthApi(Generic[ItemT]):
95
95
  metadata=self.formatter.load(result["metadata"]),
96
96
  )
97
97
 
98
+ def users_for_service(self) -> Iterable[ServiceUserInfo[ItemT]]:
99
+ result = JsonDict(
100
+ (
101
+ self.http.with_header("Authorization", f"Bearer {self.token}")
102
+ .get()
103
+ .on_endpoint(f"/services/{self.service_name}/users")
104
+ .on_failure(raises=RuntimeError)
105
+ .json()
106
+ )
107
+ )["data"]["users"]
108
+
109
+ for raw_user in result["users"]:
110
+ user = dict(raw_user["user"])
111
+ user["hashed_password"] = "unknown"
112
+
113
+ yield ServiceUserInfo[ItemT](
114
+ user=self.user_formatter.load(user),
115
+ is_superuser=bool(raw_user["is_superuser"]),
116
+ metadata=self.formatter.load(raw_user["metadata"]),
117
+ )
118
+
98
119
 
99
120
  @dataclass
100
121
  class AuthCodeApi:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: apexauthlib
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Apex authorization library for services
5
5
  Author: Apex Dev
6
6
  Author-email: dev@apex.ge
@@ -2,10 +2,10 @@ apexauthlib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  apexauthlib/entities/__init__.py,sha256=KghMo6a2QWdPzWlMqdGAKOaVvRmTCOIVhXtIHrX7A_M,149
3
3
  apexauthlib/entities/auth.py,sha256=TOs-3eNWodjrI8iFpozsNnn1KQTbPKCllbGzHSPYah8,836
4
4
  apexauthlib/fastapi/__init__.py,sha256=G77C3ZIqjsXdh4fiH5FZyF_hyzVtS3waJJGa_TBGMWE,103
5
- apexauthlib/fastapi/auth.py,sha256=rPQzLSbXEkfjF2PQXvD4XPfGtHVjBKpGuQLNl0-pZCo,3429
5
+ apexauthlib/fastapi/auth.py,sha256=hkvG2BougydElkYbEpwsuSgRoLOLANe6DbVSoa-zBRM,3917
6
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,,
7
+ apexauthlib/integration/api.py,sha256=iWkFHkkjXxJvZfBK093zq-mvAtg-g8zvpFxun74znsw,4305
8
+ apexauthlib-0.1.7.dist-info/LICENSE,sha256=iai0ILQTDgUXV1cIXl0UzSeOdFpMFK3shn5aqnz_Uro,1065
9
+ apexauthlib-0.1.7.dist-info/METADATA,sha256=Vwk84Dc9EdyV1Rh4mitJ7JW4Sgm7ibfXy8sjiHh5bmo,518
10
+ apexauthlib-0.1.7.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
+ apexauthlib-0.1.7.dist-info/RECORD,,