opengater-globalauth-client 0.1.3__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.
- opengater_globalauth_client/__init__.py +1 -1
- opengater_globalauth_client/fastapi/__init__.py +2 -0
- opengater_globalauth_client/fastapi/dependencies.py +44 -16
- {opengater_globalauth_client-0.1.3.dist-info → opengater_globalauth_client-0.1.5.dist-info}/METADATA +1 -1
- {opengater_globalauth_client-0.1.3.dist-info → opengater_globalauth_client-0.1.5.dist-info}/RECORD +6 -6
- {opengater_globalauth_client-0.1.3.dist-info → opengater_globalauth_client-0.1.5.dist-info}/WHEEL +0 -0
|
@@ -7,6 +7,7 @@ from opengater_globalauth_client.fastapi.dependencies import (
|
|
|
7
7
|
get_current_user_optional,
|
|
8
8
|
require_admin,
|
|
9
9
|
require_verified,
|
|
10
|
+
get_token,
|
|
10
11
|
)
|
|
11
12
|
|
|
12
13
|
__all__ = [
|
|
@@ -16,4 +17,5 @@ __all__ = [
|
|
|
16
17
|
"get_current_user_optional",
|
|
17
18
|
"require_admin",
|
|
18
19
|
"require_verified",
|
|
20
|
+
"get_token",
|
|
19
21
|
]
|
|
@@ -3,7 +3,8 @@ FastAPI dependencies for GlobalAuth.
|
|
|
3
3
|
"""
|
|
4
4
|
from typing import Callable
|
|
5
5
|
|
|
6
|
-
from fastapi import Request, HTTPException, Depends
|
|
6
|
+
from fastapi import Request, HTTPException, Depends
|
|
7
|
+
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
|
7
8
|
|
|
8
9
|
from opengater_globalauth_client.client import GlobalAuthClient
|
|
9
10
|
from opengater_globalauth_client.models import User
|
|
@@ -16,6 +17,10 @@ from opengater_globalauth_client.exceptions import (
|
|
|
16
17
|
)
|
|
17
18
|
|
|
18
19
|
|
|
20
|
+
# Security scheme for Swagger UI
|
|
21
|
+
_security = HTTPBearer(auto_error=False)
|
|
22
|
+
|
|
23
|
+
|
|
19
24
|
def get_current_user(client: GlobalAuthClient | None = None) -> Callable:
|
|
20
25
|
"""
|
|
21
26
|
Dependency factory for getting current authenticated user.
|
|
@@ -48,7 +53,7 @@ def get_current_user(client: GlobalAuthClient | None = None) -> Callable:
|
|
|
48
53
|
"""
|
|
49
54
|
async def dependency(
|
|
50
55
|
request: Request,
|
|
51
|
-
|
|
56
|
+
credentials: HTTPAuthorizationCredentials | None = Depends(_security),
|
|
52
57
|
) -> User:
|
|
53
58
|
# Try to get user from middleware first
|
|
54
59
|
user = getattr(request.state, USER_STATE_KEY, None)
|
|
@@ -63,13 +68,13 @@ def get_current_user(client: GlobalAuthClient | None = None) -> Callable:
|
|
|
63
68
|
detail="Auth middleware not configured and no client provided"
|
|
64
69
|
)
|
|
65
70
|
|
|
66
|
-
if not
|
|
71
|
+
if not credentials:
|
|
67
72
|
raise HTTPException(
|
|
68
73
|
status_code=401,
|
|
69
|
-
detail="Authorization
|
|
74
|
+
detail="Authorization required"
|
|
70
75
|
)
|
|
71
76
|
|
|
72
|
-
token =
|
|
77
|
+
token = credentials.credentials
|
|
73
78
|
|
|
74
79
|
try:
|
|
75
80
|
return await client.introspect(token)
|
|
@@ -107,7 +112,7 @@ def get_current_user_optional(client: GlobalAuthClient | None = None) -> Callabl
|
|
|
107
112
|
"""
|
|
108
113
|
async def dependency(
|
|
109
114
|
request: Request,
|
|
110
|
-
|
|
115
|
+
credentials: HTTPAuthorizationCredentials | None = Depends(_security),
|
|
111
116
|
) -> User | None:
|
|
112
117
|
# Try to get user from middleware
|
|
113
118
|
user = getattr(request.state, USER_STATE_KEY, None)
|
|
@@ -116,14 +121,14 @@ def get_current_user_optional(client: GlobalAuthClient | None = None) -> Callabl
|
|
|
116
121
|
return user
|
|
117
122
|
|
|
118
123
|
# No token - that's ok for optional auth
|
|
119
|
-
if not
|
|
124
|
+
if not credentials:
|
|
120
125
|
return None
|
|
121
126
|
|
|
122
127
|
# Has token - validate it
|
|
123
128
|
if client is None:
|
|
124
129
|
return None
|
|
125
130
|
|
|
126
|
-
token =
|
|
131
|
+
token = credentials.credentials
|
|
127
132
|
|
|
128
133
|
try:
|
|
129
134
|
return await client.introspect(token)
|
|
@@ -159,13 +164,12 @@ def require_admin(client: GlobalAuthClient | None = None) -> Callable:
|
|
|
159
164
|
...
|
|
160
165
|
```
|
|
161
166
|
"""
|
|
162
|
-
user_dependency = get_current_user(client)
|
|
163
|
-
|
|
164
167
|
async def dependency(
|
|
165
168
|
request: Request,
|
|
166
|
-
|
|
169
|
+
credentials: HTTPAuthorizationCredentials | None = Depends(_security),
|
|
167
170
|
) -> User:
|
|
168
|
-
|
|
171
|
+
user_dep = get_current_user(client)
|
|
172
|
+
user = await user_dep(request, credentials)
|
|
169
173
|
|
|
170
174
|
if not user.is_admin:
|
|
171
175
|
raise HTTPException(
|
|
@@ -192,13 +196,12 @@ def require_verified(client: GlobalAuthClient | None = None) -> Callable:
|
|
|
192
196
|
...
|
|
193
197
|
```
|
|
194
198
|
"""
|
|
195
|
-
user_dependency = get_current_user(client)
|
|
196
|
-
|
|
197
199
|
async def dependency(
|
|
198
200
|
request: Request,
|
|
199
|
-
|
|
201
|
+
credentials: HTTPAuthorizationCredentials | None = Depends(_security),
|
|
200
202
|
) -> User:
|
|
201
|
-
|
|
203
|
+
user_dep = get_current_user(client)
|
|
204
|
+
user = await user_dep(request, credentials)
|
|
202
205
|
|
|
203
206
|
if not user.verified:
|
|
204
207
|
raise HTTPException(
|
|
@@ -209,3 +212,28 @@ def require_verified(client: GlobalAuthClient | None = None) -> Callable:
|
|
|
209
212
|
return user
|
|
210
213
|
|
|
211
214
|
return dependency
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def get_token() -> Callable:
|
|
218
|
+
"""
|
|
219
|
+
Simple dependency to get just the token string.
|
|
220
|
+
|
|
221
|
+
Example:
|
|
222
|
+
```python
|
|
223
|
+
@app.get("/something")
|
|
224
|
+
async def something(token: str = Depends(get_token())):
|
|
225
|
+
# Use raw token
|
|
226
|
+
...
|
|
227
|
+
```
|
|
228
|
+
"""
|
|
229
|
+
async def dependency(
|
|
230
|
+
credentials: HTTPAuthorizationCredentials | None = Depends(_security),
|
|
231
|
+
) -> str:
|
|
232
|
+
if not credentials:
|
|
233
|
+
raise HTTPException(
|
|
234
|
+
status_code=401,
|
|
235
|
+
detail="Authorization required"
|
|
236
|
+
)
|
|
237
|
+
return credentials.credentials
|
|
238
|
+
|
|
239
|
+
return dependency
|
{opengater_globalauth_client-0.1.3.dist-info → opengater_globalauth_client-0.1.5.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opengater-globalauth-client
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Client library for GlobalAuth authentication service
|
|
5
5
|
Project-URL: Homepage, https://github.com/opengater/globalauth-client
|
|
6
6
|
Project-URL: Documentation, https://github.com/opengater/globalauth-client#readme
|
{opengater_globalauth_client-0.1.3.dist-info → opengater_globalauth_client-0.1.5.dist-info}/RECORD
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
opengater_globalauth_client/__init__.py,sha256=
|
|
1
|
+
opengater_globalauth_client/__init__.py,sha256=WeY_dQQQpRRGZd-n1N5vd2wHn7s1jlux9baiK-L8uvg,3102
|
|
2
2
|
opengater_globalauth_client/client.py,sha256=PPePBs_6uaYPxKhqVZOWjS7hG8bx9flA7QLOnKQy6HM,12393
|
|
3
3
|
opengater_globalauth_client/exceptions.py,sha256=0lw1UMrh7B-f6q-TAHgv5euiDwGo9PjmV7SkewSM3MQ,830
|
|
4
4
|
opengater_globalauth_client/models.py,sha256=MzULCnIF0a3YCA5tUPnQfYFd_kv5xZ9hvqI5xJ45TTI,2671
|
|
@@ -6,9 +6,9 @@ opengater_globalauth_client/broker/__init__.py,sha256=ih8b1xYcdUZSXZY1DwVqsnDbe8
|
|
|
6
6
|
opengater_globalauth_client/broker/consumer.py,sha256=2CCkp1MD5igFYDh3qlkrRtKR7E0Lk1EQ7dWxwGVEoQo,6057
|
|
7
7
|
opengater_globalauth_client/broker/events.py,sha256=nidShH1XCe7xt02gFANtq6mbjaVA5TwtnZ06qbgql4k,2674
|
|
8
8
|
opengater_globalauth_client/broker/publisher.py,sha256=mLk9yPrGG1a_0b8BlqEYPWOdrLbT2SPh77rLyKIlzNM,3698
|
|
9
|
-
opengater_globalauth_client/fastapi/__init__.py,sha256=
|
|
10
|
-
opengater_globalauth_client/fastapi/dependencies.py,sha256=
|
|
9
|
+
opengater_globalauth_client/fastapi/__init__.py,sha256=Jjk9eJD1-GIXMprJT0NAkmAb7rqFT0DPqx0s8eEI3c8,486
|
|
10
|
+
opengater_globalauth_client/fastapi/dependencies.py,sha256=P5C9PWIOsKrDwtF8LlPStPzFaMMjqXU85mQ1vuc_gn8,6912
|
|
11
11
|
opengater_globalauth_client/fastapi/middleware.py,sha256=_ySEvBH4C86VIdtuevTO8MlpSvIG8r_liLN4mpFaAls,5656
|
|
12
|
-
opengater_globalauth_client-0.1.
|
|
13
|
-
opengater_globalauth_client-0.1.
|
|
14
|
-
opengater_globalauth_client-0.1.
|
|
12
|
+
opengater_globalauth_client-0.1.5.dist-info/METADATA,sha256=XViMPR0oPl6SZM5pzgMg97Wa_y-utqFv4d7NVr_gvBA,5901
|
|
13
|
+
opengater_globalauth_client-0.1.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
14
|
+
opengater_globalauth_client-0.1.5.dist-info/RECORD,,
|
{opengater_globalauth_client-0.1.3.dist-info → opengater_globalauth_client-0.1.5.dist-info}/WHEEL
RENAMED
|
File without changes
|