FastAPI-UI-Auth 0.2.0__py3-none-any.whl → 0.2.1a0__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,14 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: FastAPI-UI-Auth
3
- Version: 0.2.0
3
+ Version: 0.2.1a0
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
7
7
  License-File: LICENSE
8
- Requires-Dist: fastapi==0.115.*
9
- Requires-Dist: jinja2==3.1.*
10
- Requires-Dist: pydantic==2.11.*
11
- Requires-Dist: python-dotenv==1.1.*
8
+ Requires-Dist: fastapi
9
+ Requires-Dist: jinja2
10
+ Requires-Dist: pydantic
11
+ Requires-Dist: python-dotenv
12
12
  Provides-Extra: dev
13
13
  Requires-Dist: websockets==15.0.*; extra == "dev"
14
14
  Requires-Dist: pre-commit==4.2.*; extra == "dev"
@@ -0,0 +1,18 @@
1
+ fastapi_ui_auth-0.2.1a0.dist-info/licenses/LICENSE,sha256=_sOIKJWdD2o1WwwDIwYB2qTP2nlSWqT5Tyg9jr1Xa4w,1070
2
+ uiauth/__init__.py,sha256=s8r2Z0O9w3cuw7GcmRTOWY0NZC0KJXzBS9QsG9wUWsk,264
3
+ uiauth/endpoints.py,sha256=CJteXsGQWfn--U6_VdVN8VhnPsf3HSefYX1NOzAhacM,2837
4
+ uiauth/enums.py,sha256=WO0eBv3l9HHr1I_ZXtAifCgdL-db_tZj9ka7jnjiS5k,547
5
+ uiauth/logger.py,sha256=z67PBMs4zWOfy-Gfm_41dj5Uulm-ChvZxB_jmYKKXeI,391
6
+ uiauth/models.py,sha256=dH207dqVybK_qPzzm2RuMxZBamoFm8zO5tk7jmyGStM,3719
7
+ uiauth/secure.py,sha256=ZOH6kT4BD56VqwaKdKocX7eSE8tqZcu-tK0QOmjY58k,1089
8
+ uiauth/service.py,sha256=DJnK9PsBg9CnWiIqWRt7Aa7ZXncTUm5W8jZmA9UJK5Q,6659
9
+ uiauth/utils.py,sha256=DzXqxLpKHUDy1bxffg1cw0izqxcgmnCybSytywiPgbQ,6625
10
+ uiauth/version.py,sha256=nJo0rYXinOLv3d1ZFH-u19fo0iIADpBZFIy8nNqi3wg,24
11
+ uiauth/templates/index.html,sha256=n8tOiKXEUI4zBh1YOQNlH5MKNMRTQ2adH0QIuvrEcv4,9071
12
+ uiauth/templates/logout.html,sha256=JrWBJCbK1E4NfrNipMsLzfJ_-Fs2C6D4S0B6O7JNoek,3504
13
+ uiauth/templates/session.html,sha256=EL4gajOED3IcOnrALMiJ2SzJl2at8GFfruTuExhgOVI,3040
14
+ uiauth/templates/unauthorized.html,sha256=ahv78zLM04_Lu83LdX0Ua_toKeP5JZkYsTCWCrfCvHA,3002
15
+ fastapi_ui_auth-0.2.1a0.dist-info/METADATA,sha256=1mPPvL2iv9mXJmUBsPmAA7IdXtOQKNggEiR5mBkAKoc,3524
16
+ fastapi_ui_auth-0.2.1a0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
+ fastapi_ui_auth-0.2.1a0.dist-info/top_level.txt,sha256=ra3nGTbDTgQ7eChlkngJ7xGXhSCeFTWMvb_b6q8uPVA,7
18
+ fastapi_ui_auth-0.2.1a0.dist-info/RECORD,,
uiauth/endpoints.py CHANGED
@@ -1,7 +1,8 @@
1
+ from fastapi.exceptions import HTTPException
1
2
  from fastapi.requests import Request
2
3
  from fastapi.responses import HTMLResponse
3
4
 
4
- from uiauth import enums, models, utils
5
+ from uiauth import enums, logger, models, utils
5
6
  from uiauth.version import version
6
7
 
7
8
 
@@ -49,6 +50,30 @@ def login(request: Request) -> HTMLResponse:
49
50
  )
50
51
 
51
52
 
53
+ def logout(request: Request) -> HTMLResponse:
54
+ """Render the logout page with the verification path and version.
55
+
56
+ Returns:
57
+ HTMLResponse:
58
+ Rendered HTML response for the logout page.
59
+ """
60
+ try:
61
+ utils.verify_session(request)
62
+ except (models.RedirectException, HTTPException):
63
+ logger.CUSTOM_LOGGER.warning("Invalid session")
64
+ return session(request)
65
+ return utils.deauthorize(
66
+ models.templates.TemplateResponse(
67
+ name="logout.html",
68
+ context={
69
+ "request": request,
70
+ "detail": "You have been successfully logged out.",
71
+ "version": f"v{version}",
72
+ },
73
+ ),
74
+ )
75
+
76
+
52
77
  def error(request: Request) -> HTMLResponse:
53
78
  """Error endpoint for the authenticator.
54
79
 
uiauth/models.py CHANGED
@@ -4,7 +4,7 @@ from typing import Callable, Dict, List, Optional, Type
4
4
 
5
5
  from fastapi.routing import APIRoute, APIWebSocketRoute
6
6
  from fastapi.templating import Jinja2Templates
7
- from pydantic import BaseModel, Field, ValidationInfo, field_validator
7
+ from pydantic import BaseModel, Field
8
8
 
9
9
  from uiauth.enums import APIMethods
10
10
 
@@ -32,30 +32,17 @@ def get_env(keys: List[str], default: Optional[str] = None) -> Optional[str]:
32
32
 
33
33
 
34
34
  class EnvConfig(BaseModel):
35
- """Configuration for environment variables."""
35
+ """Configuration for environment variables.
36
36
 
37
- username: str
38
- password: str
37
+ >>> EnvConfig
39
38
 
40
- # noinspection PyMethodParameters
41
- @field_validator("username", "password", mode="before")
42
- def load_user(cls, key: str, field: ValidationInfo) -> str | None:
43
- """Load environment variables into the configuration.
44
-
45
- Args:
46
- key: Environment variable key to check.
47
- field: Field information for validation.
48
-
49
- See Also:
50
- - This method checks if the environment variable is set and returns its value.
51
- - If the key is not set, it attempts to get the value from the environment using a helper function.
39
+ See Also:
40
+ - Tries to resolve username and password through kwargs.
41
+ - Uses environment variables as fallback.
42
+ """
52
43
 
53
- Returns:
54
- str | None:
55
- Value of the environment variable or None if not set.
56
- """
57
- if not key:
58
- return get_env([field.field_name, field.field_name[:4]])
44
+ username: str = Field(default_factory=lambda: get_env(("username", "user")))
45
+ password: str = Field(default_factory=lambda: get_env(("password", "pass")))
59
46
 
60
47
 
61
48
  env = EnvConfig
uiauth/service.py CHANGED
@@ -132,6 +132,11 @@ class FastAPIUIAuth:
132
132
  endpoint=endpoints.login,
133
133
  methods=["GET"],
134
134
  )
135
+ logout_route = APIRoute(
136
+ path=enums.APIEndpoints.fastapi_logout,
137
+ endpoint=endpoints.logout,
138
+ methods=["GET"],
139
+ )
135
140
  error_route = APIRoute(
136
141
  path=enums.APIEndpoints.fastapi_error,
137
142
  endpoint=endpoints.error,
@@ -163,4 +168,6 @@ class FastAPIUIAuth:
163
168
  dependencies=[Depends(utils.verify_session)],
164
169
  )
165
170
  self.app.routes.append(secure_route)
166
- self.app.routes.extend([login_route, session_route, verify_route, error_route])
171
+ self.app.routes.extend(
172
+ [login_route, logout_route, session_route, verify_route, error_route]
173
+ )
@@ -239,8 +239,8 @@
239
239
  </script>
240
240
  <footer>
241
241
  <div class="footer">
242
- PyAPIAuthenticator - {{ version }}<br>
243
- <a href="https://github.com/thevickypedia/pyapiauthenticator">https://github.com/thevickypedia/pyapiauthenticator</a>
242
+ FastAPI-UI-Auth - {{ version }}<br>
243
+ <a href="https://github.com/thevickypedia/FastAPI-UI-Auth">https://github.com/thevickypedia/FastAPI-UI-Auth</a>
244
244
  </div>
245
245
  </footer>
246
246
  <script>
@@ -0,0 +1,94 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+ <title>FastAPI UI Authentication</title>
6
+ <meta property="og:type" content="Authenticator">
7
+ <meta name="keywords" content="Python, fastapi, JavaScript, HTML, CSS">
8
+ <meta name="author" content="Vignesh Rao">
9
+ <meta content="width=device-width, initial-scale=1" name="viewport">
10
+ <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
12
+ <!-- Favicon.ico and Apple Touch Icon -->
13
+ <link property="og:image" rel="icon" href="https://thevickypedia.github.io/open-source/images/logo/fastapi.ico">
14
+ <link property="og:image" rel="apple-touch-icon"
15
+ href="https://thevickypedia.github.io/open-source/images/logo/fastapi.png">
16
+ <!-- Font Awesome icons -->
17
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/fontawesome.min.css">
18
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/solid.min.css">
19
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/regular.min.css">
20
+ <style>
21
+ img {
22
+ display: block;
23
+ margin-left: auto;
24
+ margin-right: auto;
25
+ }
26
+
27
+ :is(h1, h2, h3, h4, h5, h6) {
28
+ text-align: center;
29
+ color: #F0F0F0;
30
+ font-family: 'Courier New', sans-serif;
31
+ }
32
+
33
+ button {
34
+ width: 100px;
35
+ margin: 0 auto;
36
+ display: block;
37
+ }
38
+
39
+ body {
40
+ background-color: #151515;
41
+ }
42
+
43
+ footer {
44
+ bottom: 20px;
45
+ position: fixed;
46
+ width: 100%;
47
+ color: #fff;
48
+ text-align: center;
49
+ font-family: 'Courier New', monospace;
50
+ font-size: small;
51
+ }
52
+ </style>
53
+ <noscript>
54
+ <style>
55
+ body {
56
+ width: 100%;
57
+ height: 100%;
58
+ overflow: hidden;
59
+ }
60
+ </style>
61
+ <div style="position: fixed; text-align:center; height: 100%; width: 100%; background-color: #151515;">
62
+ <h2 style="margin-top:5%">This page requires JavaScript
63
+ to be enabled.
64
+ <br><br>
65
+ Please refer <a href="https://www.enable-javascript.com/">enable-javascript</a> for how to.
66
+ </h2>
67
+ <form>
68
+ <button type="submit" onClick="<meta httpEquiv='refresh' content='0'>">RETRY</button>
69
+ </form>
70
+ </div>
71
+ </noscript>
72
+ </head>
73
+ <body>
74
+ <h2 style="margin-top:5%">LOGOUT</h2>
75
+ <h3>{{ detail }}</h3>
76
+ <p>
77
+ <img src="https://thevickypedia.github.io/open-source/images/gif/blended_fusion.gif"
78
+ onerror="this.src='https://vigneshrao.com/open-source/images/gif/blended_fusion.gif'"
79
+ width="200" height="200" alt="Image" class="center">
80
+ </p>
81
+ {% if show_login %}
82
+ <button style="text-align:center" onClick="window.location.href = '/monitor';">LOGIN</button>
83
+ {% else %}
84
+ <h3>Please close the session window</h3>
85
+ {% endif %}
86
+ <h4>Click <a href="https://vigneshrao.com/contact">HERE</a> to reach out.</h4>
87
+ </body>
88
+ <footer>
89
+ <div class="footer">
90
+ FastAPI-UI-Auth - {{ version }}<br>
91
+ <a href="https://github.com/thevickypedia/FastAPI-UI-Auth">https://github.com/thevickypedia/FastAPI-UI-Auth</a>
92
+ </div>
93
+ </footer>
94
+ </html>
uiauth/version.py CHANGED
@@ -1 +1 @@
1
- version = "0.2.0"
1
+ version = "0.2.1-alpha"
@@ -1,17 +0,0 @@
1
- fastapi_ui_auth-0.2.0.dist-info/licenses/LICENSE,sha256=_sOIKJWdD2o1WwwDIwYB2qTP2nlSWqT5Tyg9jr1Xa4w,1070
2
- uiauth/__init__.py,sha256=s8r2Z0O9w3cuw7GcmRTOWY0NZC0KJXzBS9QsG9wUWsk,264
3
- uiauth/endpoints.py,sha256=4RtabYwlNSHAqpU89zfRH8RD_ATH1AAf-lJKg4HA1RQ,2076
4
- uiauth/enums.py,sha256=WO0eBv3l9HHr1I_ZXtAifCgdL-db_tZj9ka7jnjiS5k,547
5
- uiauth/logger.py,sha256=z67PBMs4zWOfy-Gfm_41dj5Uulm-ChvZxB_jmYKKXeI,391
6
- uiauth/models.py,sha256=lcJyy99c-VeSeUj3LahXisQZ4g3wRqdGtBVdL1oyaZI,4255
7
- uiauth/secure.py,sha256=ZOH6kT4BD56VqwaKdKocX7eSE8tqZcu-tK0QOmjY58k,1089
8
- uiauth/service.py,sha256=6CN3Rg8m3f83sJuLdswVzwkxkwkjptHgWa5uugxIccE,6460
9
- uiauth/utils.py,sha256=DzXqxLpKHUDy1bxffg1cw0izqxcgmnCybSytywiPgbQ,6625
10
- uiauth/version.py,sha256=XQVhijSHeIVMVzY2S4fY9BKxV2XHSTr9VVHsYltGPvQ,18
11
- uiauth/templates/index.html,sha256=8vbONgCdhBmwe12ITeuBSjwwjp309kDS9cu2lRrrG88,9080
12
- uiauth/templates/session.html,sha256=EL4gajOED3IcOnrALMiJ2SzJl2at8GFfruTuExhgOVI,3040
13
- uiauth/templates/unauthorized.html,sha256=ahv78zLM04_Lu83LdX0Ua_toKeP5JZkYsTCWCrfCvHA,3002
14
- fastapi_ui_auth-0.2.0.dist-info/METADATA,sha256=L10c3aWSYOwNnAQIcbVO4SzBVH7Xa6DhueQViFlmW_o,3553
15
- fastapi_ui_auth-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- fastapi_ui_auth-0.2.0.dist-info/top_level.txt,sha256=ra3nGTbDTgQ7eChlkngJ7xGXhSCeFTWMvb_b6q8uPVA,7
17
- fastapi_ui_auth-0.2.0.dist-info/RECORD,,