apexauthlib 0.1.3__py3-none-any.whl → 0.1.4__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.
@@ -33,3 +33,9 @@ class ServiceMetadata:
33
33
  class UserMetadata:
34
34
  service: str
35
35
  metadata: dict[str, Any]
36
+
37
+
38
+ @dataclass(frozen=True)
39
+ class Client:
40
+ client_id: str
41
+ hashed_secret: str
@@ -7,10 +7,11 @@ from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
7
7
  from starlette import status
8
8
 
9
9
  from apexauthlib.entities import User
10
- from apexauthlib.integration.api import AuthApiProvider
10
+ from apexauthlib.integration.api import AuthApiProvider, AuthCodeApi
11
11
 
12
12
  auth_api = APIRouter(tags=["Auth"])
13
13
  AuthApiProviderDependable = Annotated[AuthApiProvider[Any], inject("auth")]
14
+ AuthCodeApiDependable = Annotated[AuthCodeApi, inject("auth_code")]
14
15
 
15
16
 
16
17
  def oauth2() -> OAuth2PasswordBearer:
@@ -90,3 +91,23 @@ def login(
90
91
  status_code=status.HTTP_401_UNAUTHORIZED,
91
92
  detail="Incorrect username or password",
92
93
  )
94
+
95
+
96
+ @auth_api.post(
97
+ "/login/code",
98
+ status_code=200,
99
+ response_model=TokenResponse,
100
+ )
101
+ def login_code(
102
+ code: str,
103
+ auth_code: AuthCodeApiDependable,
104
+ ) -> TokenResponse:
105
+ try:
106
+ return TokenResponse(
107
+ access_token=auth_code.token_for(code),
108
+ )
109
+ except Exception:
110
+ raise HTTPException(
111
+ status_code=status.HTTP_401_UNAUTHORIZED,
112
+ detail="Incorrect username or password",
113
+ )
@@ -71,3 +71,27 @@ class AuthApi(Generic[ItemT]):
71
71
  )
72
72
 
73
73
  return self.formatter.load(JsonDict(result["data"]["metadata"]["metadata"]))
74
+
75
+
76
+ @dataclass
77
+ class AuthCodeApi:
78
+ http: FluentHttp
79
+ client_id: str
80
+ client_secret: str
81
+
82
+ def token_for(self, code: str) -> str:
83
+ data = {
84
+ "code": code,
85
+ "client_id": self.client_id,
86
+ "client_secret": self.client_secret,
87
+ }
88
+
89
+ return str(
90
+ (
91
+ self.http.with_data(JsonDict(data))
92
+ .post()
93
+ .on_endpoint("/auth/oauth/token")
94
+ .on_failure(raises=RuntimeError)
95
+ .json()
96
+ )["access_token"]
97
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: apexauthlib
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: Apex authorization library for services
5
5
  Author: Apex Dev
6
6
  Author-email: dev@apex.ge
@@ -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=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,,
@@ -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=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.3.dist-info/LICENSE,sha256=iai0ILQTDgUXV1cIXl0UzSeOdFpMFK3shn5aqnz_Uro,1065
9
- apexauthlib-0.1.3.dist-info/METADATA,sha256=01uzJAMGCcLsX4RExqcrjZgSBTZ0RDjk7DECuKv2FT0,518
10
- apexauthlib-0.1.3.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
11
- apexauthlib-0.1.3.dist-info/RECORD,,