FastAPI-UI-Auth 0.3.0__py3-none-any.whl → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: FastAPI-UI-Auth
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Python module to add username and password authentication to specific FastAPI routes
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -1,18 +1,18 @@
1
- fastapi_ui_auth-0.3.0.dist-info/licenses/LICENSE,sha256=_sOIKJWdD2o1WwwDIwYB2qTP2nlSWqT5Tyg9jr1Xa4w,1070
1
+ fastapi_ui_auth-0.3.2.dist-info/licenses/LICENSE,sha256=_sOIKJWdD2o1WwwDIwYB2qTP2nlSWqT5Tyg9jr1Xa4w,1070
2
2
  uiauth/__init__.py,sha256=hbHN-Vv4xTxDqpQW2lmgdl-OlEkAtL6JXAGL-nucaOU,211
3
- uiauth/endpoints.py,sha256=CJteXsGQWfn--U6_VdVN8VhnPsf3HSefYX1NOzAhacM,2837
3
+ uiauth/endpoints.py,sha256=nacWM8IJWnReweMwsDOEffyPKXll_qtXnGTSA4NJysY,2953
4
4
  uiauth/enums.py,sha256=W_9U2luXbscyBEROXqEhKY5DHpJRV1J4VUOpkyUOOzU,334
5
5
  uiauth/logger.py,sha256=z67PBMs4zWOfy-Gfm_41dj5Uulm-ChvZxB_jmYKKXeI,391
6
6
  uiauth/models.py,sha256=56d8O9bExxwPZcOzMYL0IN9LOnVTJyfOSvD58kzTklc,3210
7
7
  uiauth/secure.py,sha256=ZOH6kT4BD56VqwaKdKocX7eSE8tqZcu-tK0QOmjY58k,1089
8
- uiauth/service.py,sha256=amj7899oG9PP3-HHMo_2OMjiBpUXnUUli9at1FQwwMw,7992
9
- uiauth/utils.py,sha256=WdkR3Ro6KLacBiCFZECaH377JqhsMWVCGF2SjGSxXRg,6989
10
- uiauth/version.py,sha256=EqIccytbgmIh3EOfv7QIiksdjJSlB-o2LbyXxRtoMGs,18
8
+ uiauth/service.py,sha256=XeVFxWR5k7QIdgxjRBiUaE0oYpSlX3HE-RadJq-7HW4,7827
9
+ uiauth/utils.py,sha256=Ga8RivN3PJX8zg2uu3RfEtJLGKaT1_iwphqvhh2XrPY,7007
10
+ uiauth/version.py,sha256=zjuPzQ2OlxNtrLXb5A3OlPsaRb_b_Ln51AWN6r9VRho,18
11
11
  uiauth/templates/index.html,sha256=n8tOiKXEUI4zBh1YOQNlH5MKNMRTQ2adH0QIuvrEcv4,9071
12
12
  uiauth/templates/logout.html,sha256=JrWBJCbK1E4NfrNipMsLzfJ_-Fs2C6D4S0B6O7JNoek,3504
13
13
  uiauth/templates/session.html,sha256=EL4gajOED3IcOnrALMiJ2SzJl2at8GFfruTuExhgOVI,3040
14
14
  uiauth/templates/unauthorized.html,sha256=ahv78zLM04_Lu83LdX0Ua_toKeP5JZkYsTCWCrfCvHA,3002
15
- fastapi_ui_auth-0.3.0.dist-info/METADATA,sha256=o8U9Nz2gvix5n5WdqwF4eJeYxC4LEqQv4m2gvuxkUlw,3662
16
- fastapi_ui_auth-0.3.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
17
- fastapi_ui_auth-0.3.0.dist-info/top_level.txt,sha256=ra3nGTbDTgQ7eChlkngJ7xGXhSCeFTWMvb_b6q8uPVA,7
18
- fastapi_ui_auth-0.3.0.dist-info/RECORD,,
15
+ fastapi_ui_auth-0.3.2.dist-info/METADATA,sha256=Yx80vcs80ZJtOEmn3uJcJ3MaIUXJ1p7KZHTOkGt2bIg,3662
16
+ fastapi_ui_auth-0.3.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
17
+ fastapi_ui_auth-0.3.2.dist-info/top_level.txt,sha256=ra3nGTbDTgQ7eChlkngJ7xGXhSCeFTWMvb_b6q8uPVA,7
18
+ fastapi_ui_auth-0.3.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.0)
2
+ Generator: setuptools (82.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
uiauth/endpoints.py CHANGED
@@ -19,6 +19,7 @@ def session(request: Request) -> HTMLResponse:
19
19
  return utils.deauthorize(
20
20
  models.templates.TemplateResponse(
21
21
  name="session.html",
22
+ request=request,
22
23
  context={
23
24
  "request": request,
24
25
  "signin": enums.APIEndpoints.fastapi_login,
@@ -41,6 +42,7 @@ def login(request: Request) -> HTMLResponse:
41
42
  return utils.deauthorize(
42
43
  models.templates.TemplateResponse(
43
44
  name="index.html",
45
+ request=request,
44
46
  context={
45
47
  "request": request,
46
48
  "signin": enums.APIEndpoints.fastapi_verify_login,
@@ -65,6 +67,7 @@ def logout(request: Request) -> HTMLResponse:
65
67
  return utils.deauthorize(
66
68
  models.templates.TemplateResponse(
67
69
  name="logout.html",
70
+ request=request,
68
71
  context={
69
72
  "request": request,
70
73
  "detail": "You have been successfully logged out.",
@@ -87,6 +90,7 @@ def error(request: Request) -> HTMLResponse:
87
90
  return utils.deauthorize(
88
91
  models.templates.TemplateResponse(
89
92
  name="unauthorized.html",
93
+ request=request,
90
94
  context={
91
95
  "request": request,
92
96
  "signin": enums.APIEndpoints.fastapi_login,
uiauth/service.py CHANGED
@@ -1,3 +1,4 @@
1
+ import inspect
1
2
  import logging
2
3
  import time
3
4
  from typing import Dict, List
@@ -139,26 +140,31 @@ class FastAPIUIAuth:
139
140
  path=enums.APIEndpoints.fastapi_login,
140
141
  endpoint=endpoints.login,
141
142
  methods=["GET"],
143
+ include_in_schema=False,
142
144
  )
143
145
  logout_route = APIRoute(
144
146
  path=enums.APIEndpoints.fastapi_logout,
145
147
  endpoint=endpoints.logout,
146
148
  methods=["GET"],
149
+ include_in_schema=False,
147
150
  )
148
151
  error_route = APIRoute(
149
152
  path=enums.APIEndpoints.fastapi_error,
150
153
  endpoint=endpoints.error,
151
154
  methods=["GET"],
155
+ include_in_schema=False,
152
156
  )
153
157
  session_route = APIRoute(
154
158
  path=enums.APIEndpoints.fastapi_session,
155
159
  endpoint=endpoints.session,
156
160
  methods=["GET"],
161
+ include_in_schema=False,
157
162
  )
158
163
  verify_route = APIRoute(
159
164
  path=enums.APIEndpoints.fastapi_verify_login,
160
165
  endpoint=self._verify_auth,
161
166
  methods=["POST"],
167
+ include_in_schema=False,
162
168
  )
163
169
  protected_paths = {route.path for route in self.routes}
164
170
  conflicting = [
@@ -174,22 +180,15 @@ class FastAPIUIAuth:
174
180
  )
175
181
  self.app.routes.remove(existing)
176
182
  for route in self.routes:
177
- # WebSocket routes will not have a login path, they will be protected by session check
178
- if isinstance(route, APIWebSocketRoute):
179
- secure_route = APIWebSocketRoute(
180
- path=route.path,
181
- endpoint=route.endpoint,
182
- dependencies=list(route.dependencies)
183
- + [Depends(utils.verify_session)],
184
- )
185
- else:
186
- secure_route = APIRoute(
187
- path=route.path,
188
- endpoint=route.endpoint,
189
- methods=list(route.methods) if route.methods else ["GET"],
190
- dependencies=list(route.dependencies)
191
- + [Depends(utils.verify_session)],
192
- )
183
+ kwargs = {
184
+ name: getattr(route, name)
185
+ for name in inspect.signature(route.__class__.__init__).parameters
186
+ if name != "self" and hasattr(route, name)
187
+ }
188
+ kwargs["dependencies"] = list(route.dependencies) + [
189
+ Depends(utils.verify_session)
190
+ ]
191
+ secure_route = route.__class__(**kwargs)
193
192
  self.app.routes.append(secure_route)
194
193
  self.app.routes.extend(
195
194
  [login_route, logout_route, session_route, verify_route, error_route]
uiauth/utils.py CHANGED
@@ -138,14 +138,14 @@ def verify_session(
138
138
  detail="Request or WebSocket connection is required for session check.",
139
139
  )
140
140
  session_token = request.cookies.get("session_token")
141
- stored = models.ws_session.client_auth.get(request.client.host)
141
+ stored = models.ws_session.client_auth.get(request.client.host, {})
142
142
  if (
143
- stored
143
+ stored.get("token")
144
144
  and session_token
145
145
  and secrets.compare_digest(session_token, stored["token"])
146
146
  ):
147
147
  if time.time() < stored["expires_at"]:
148
- logger.CUSTOM_LOGGER.info(
148
+ logger.CUSTOM_LOGGER.debug(
149
149
  "Session is valid for host: %s", request.client.host
150
150
  )
151
151
  return
uiauth/version.py CHANGED
@@ -1 +1 @@
1
- version = "0.3.0"
1
+ version = "0.3.2"