FastAPI-UI-Auth 0.2.1a0__py3-none-any.whl → 0.2.3__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.
- {fastapi_ui_auth-0.2.1a0.dist-info → fastapi_ui_auth-0.2.3.dist-info}/METADATA +2 -3
- {fastapi_ui_auth-0.2.1a0.dist-info → fastapi_ui_auth-0.2.3.dist-info}/RECORD +8 -8
- {fastapi_ui_auth-0.2.1a0.dist-info → fastapi_ui_auth-0.2.3.dist-info}/WHEEL +1 -1
- uiauth/models.py +29 -19
- uiauth/service.py +17 -3
- uiauth/version.py +1 -1
- {fastapi_ui_auth-0.2.1a0.dist-info → fastapi_ui_auth-0.2.3.dist-info}/licenses/LICENSE +0 -0
- {fastapi_ui_auth-0.2.1a0.dist-info → fastapi_ui_auth-0.2.3.dist-info}/top_level.txt +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: FastAPI-UI-Auth
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
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
8
|
Requires-Dist: fastapi
|
|
9
|
-
Requires-Dist:
|
|
9
|
+
Requires-Dist: Jinja2
|
|
10
10
|
Requires-Dist: pydantic
|
|
11
|
-
Requires-Dist: python-dotenv
|
|
12
11
|
Provides-Extra: dev
|
|
13
12
|
Requires-Dist: websockets==15.0.*; extra == "dev"
|
|
14
13
|
Requires-Dist: pre-commit==4.2.*; extra == "dev"
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
fastapi_ui_auth-0.2.
|
|
1
|
+
fastapi_ui_auth-0.2.3.dist-info/licenses/LICENSE,sha256=_sOIKJWdD2o1WwwDIwYB2qTP2nlSWqT5Tyg9jr1Xa4w,1070
|
|
2
2
|
uiauth/__init__.py,sha256=s8r2Z0O9w3cuw7GcmRTOWY0NZC0KJXzBS9QsG9wUWsk,264
|
|
3
3
|
uiauth/endpoints.py,sha256=CJteXsGQWfn--U6_VdVN8VhnPsf3HSefYX1NOzAhacM,2837
|
|
4
4
|
uiauth/enums.py,sha256=WO0eBv3l9HHr1I_ZXtAifCgdL-db_tZj9ka7jnjiS5k,547
|
|
5
5
|
uiauth/logger.py,sha256=z67PBMs4zWOfy-Gfm_41dj5Uulm-ChvZxB_jmYKKXeI,391
|
|
6
|
-
uiauth/models.py,sha256=
|
|
6
|
+
uiauth/models.py,sha256=cU1VoPtHsB0A8DIvXSDpAZz2KtbOtQPB507cQ4MGeOw,4014
|
|
7
7
|
uiauth/secure.py,sha256=ZOH6kT4BD56VqwaKdKocX7eSE8tqZcu-tK0QOmjY58k,1089
|
|
8
|
-
uiauth/service.py,sha256=
|
|
8
|
+
uiauth/service.py,sha256=sJG-RbiiO-qKtvaGrSsu_UfTndRPkdRn0AXWhGnjJmQ,7443
|
|
9
9
|
uiauth/utils.py,sha256=DzXqxLpKHUDy1bxffg1cw0izqxcgmnCybSytywiPgbQ,6625
|
|
10
|
-
uiauth/version.py,sha256=
|
|
10
|
+
uiauth/version.py,sha256=7YVXTLSKw_SIjam_Lv65ld1ty1jiyVmclya8_CjMMqY,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.2.
|
|
16
|
-
fastapi_ui_auth-0.2.
|
|
17
|
-
fastapi_ui_auth-0.2.
|
|
18
|
-
fastapi_ui_auth-0.2.
|
|
15
|
+
fastapi_ui_auth-0.2.3.dist-info/METADATA,sha256=QeOE9sG3SJE5Tzqm7AoOe65z8QjgqcS_t_mSmFJHYBU,3493
|
|
16
|
+
fastapi_ui_auth-0.2.3.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
17
|
+
fastapi_ui_auth-0.2.3.dist-info/top_level.txt,sha256=ra3nGTbDTgQ7eChlkngJ7xGXhSCeFTWMvb_b6q8uPVA,7
|
|
18
|
+
fastapi_ui_auth-0.2.3.dist-info/RECORD,,
|
uiauth/models.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import pathlib
|
|
3
|
-
from typing import Callable, Dict, List, Optional, Type
|
|
3
|
+
from typing import Callable, Dict, Iterable, List, Optional, Type
|
|
4
4
|
|
|
5
5
|
from fastapi.routing import APIRoute, APIWebSocketRoute
|
|
6
6
|
from fastapi.templating import Jinja2Templates
|
|
@@ -11,38 +11,48 @@ from uiauth.enums import APIMethods
|
|
|
11
11
|
templates = Jinja2Templates(directory=pathlib.Path(__file__).parent / "templates")
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
"""
|
|
14
|
+
class EnvConfig(BaseModel):
|
|
15
|
+
"""Model for environment configuration.
|
|
16
|
+
|
|
17
|
+
>>> EnvConfig
|
|
18
|
+
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
username: str
|
|
22
|
+
password: str
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_cred(keys: Iterable[str], kwargs: Dict[str, str]) -> str | None:
|
|
26
|
+
"""Helper function to retrieve credentials from kwargs or environment variables.
|
|
16
27
|
|
|
17
28
|
Args:
|
|
18
|
-
keys:
|
|
19
|
-
|
|
29
|
+
keys: Iterable of keys to look for in kwargs and environment variables.
|
|
30
|
+
kwargs: Key-value pairs to search for credentials, takes precedence over environment variables.
|
|
20
31
|
|
|
21
32
|
Returns:
|
|
22
|
-
|
|
33
|
+
str | None:
|
|
34
|
+
The first found credential value or None if not found.
|
|
23
35
|
"""
|
|
24
36
|
for key in keys:
|
|
25
|
-
if value := os.getenv(key):
|
|
37
|
+
if value := kwargs.get(key) or os.getenv(key):
|
|
26
38
|
return value
|
|
27
|
-
|
|
28
|
-
return value
|
|
29
|
-
if value := os.getenv(key.lower()):
|
|
30
|
-
return value
|
|
31
|
-
return default
|
|
39
|
+
return None
|
|
32
40
|
|
|
33
41
|
|
|
34
|
-
|
|
35
|
-
"""
|
|
36
|
-
|
|
37
|
-
>>> EnvConfig
|
|
42
|
+
def env_loader(**kwargs) -> EnvConfig:
|
|
43
|
+
"""Loads environment variables into the EnvConfig model.
|
|
38
44
|
|
|
39
45
|
See Also:
|
|
40
46
|
- Tries to resolve username and password through kwargs.
|
|
41
47
|
- Uses environment variables as fallback.
|
|
42
|
-
"""
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
Returns:
|
|
50
|
+
EnvConfig:
|
|
51
|
+
An instance of EnvConfig with loaded environment variables.
|
|
52
|
+
"""
|
|
53
|
+
username = get_cred(["username", "USERNAME", "user", "USER"], kwargs)
|
|
54
|
+
password = get_cred(["password", "PASSWORD", "pass", "PASS"], kwargs)
|
|
55
|
+
return EnvConfig(username=username, password=password)
|
|
46
56
|
|
|
47
57
|
|
|
48
58
|
env = EnvConfig
|
uiauth/service.py
CHANGED
|
@@ -2,7 +2,6 @@ import logging
|
|
|
2
2
|
from threading import Timer
|
|
3
3
|
from typing import Dict, List
|
|
4
4
|
|
|
5
|
-
import dotenv
|
|
6
5
|
from fastapi import status
|
|
7
6
|
from fastapi.applications import FastAPI
|
|
8
7
|
from fastapi.exceptions import HTTPException
|
|
@@ -14,7 +13,6 @@ from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
|
|
14
13
|
|
|
15
14
|
from uiauth import endpoints, enums, logger, models, utils
|
|
16
15
|
|
|
17
|
-
dotenv.load_dotenv(dotenv_path=dotenv.find_dotenv(), override=True)
|
|
18
16
|
BEARER_AUTH = HTTPBearer()
|
|
19
17
|
|
|
20
18
|
|
|
@@ -26,6 +24,9 @@ class FastAPIUIAuth:
|
|
|
26
24
|
|
|
27
25
|
"""
|
|
28
26
|
|
|
27
|
+
# TODO: Consume APIRoute or APIWebSocketRoute directly in params instead of creating them in the _secure method
|
|
28
|
+
# Include stricter type validation (if that works)
|
|
29
|
+
# Update samples and readme - major version change
|
|
29
30
|
def __init__(
|
|
30
31
|
self,
|
|
31
32
|
app: FastAPI,
|
|
@@ -50,15 +51,28 @@ class FastAPIUIAuth:
|
|
|
50
51
|
custom_logger: Custom logger instance, defaults to the custom logger.
|
|
51
52
|
"""
|
|
52
53
|
models.env = models.EnvConfig(username=username, password=password)
|
|
53
|
-
assert
|
|
54
|
+
assert (
|
|
55
|
+
models.env.username and models.env.password
|
|
56
|
+
), "Username and password must be provided either as arguments or environment variables"
|
|
57
|
+
assert isinstance(app, FastAPI), "App must be an instance of FastAPI"
|
|
54
58
|
|
|
55
59
|
self.app = app
|
|
56
60
|
|
|
57
61
|
if isinstance(params, list):
|
|
62
|
+
assert len(params) > 0, "No endpoints to register"
|
|
63
|
+
for param in params:
|
|
64
|
+
assert isinstance(
|
|
65
|
+
param, models.Parameters
|
|
66
|
+
), f"{param} must be an instance of models.Parameters"
|
|
58
67
|
self.params = params
|
|
59
68
|
elif isinstance(params, models.Parameters):
|
|
60
69
|
self.params = [params]
|
|
70
|
+
else:
|
|
71
|
+
raise ValueError(
|
|
72
|
+
"Params must be an instance of Parameters or a list of Parameters"
|
|
73
|
+
)
|
|
61
74
|
|
|
75
|
+
assert fallback_path.startswith("/"), "Fallback path must start with '/'"
|
|
62
76
|
models.fallback.path = fallback_path
|
|
63
77
|
models.fallback.button = fallback_button
|
|
64
78
|
|
uiauth/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
version = "0.2.
|
|
1
|
+
version = "0.2.3"
|
|
File without changes
|
|
File without changes
|