xn-auth 0.2.2.dev3__tar.gz → 0.2.3__tar.gz
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.
- {xn_auth-0.2.2.dev3/xn_auth.egg-info → xn_auth-0.2.3}/PKG-INFO +1 -2
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/pyproject.toml +2 -3
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/x_auth/__init__.py +4 -3
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/x_auth/pydantic.py +3 -11
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/x_auth/router.py +23 -4
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3/xn_auth.egg-info}/PKG-INFO +1 -2
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/xn_auth.egg-info/requires.txt +0 -1
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/.env.dist +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/.gitignore +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/.pre-commit-config.yaml +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/README.md +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/makefile +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/setup.cfg +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/x_auth/backend.py +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/x_auth/depend.py +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/x_auth/enums.py +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/x_auth/models.py +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/xn_auth.egg-info/SOURCES.txt +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/xn_auth.egg-info/dependency_links.txt +0 -0
- {xn_auth-0.2.2.dev3 → xn_auth-0.2.3}/xn_auth.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: xn-auth
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Auth adapter for XN-Api framework
|
|
5
5
|
Author-email: Artemiev <mixartemev@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -16,7 +16,6 @@ Requires-Dist: xn-model
|
|
|
16
16
|
Provides-Extra: dev
|
|
17
17
|
Requires-Dist: build; extra == "dev"
|
|
18
18
|
Requires-Dist: python-dotenv; extra == "dev"
|
|
19
|
-
Requires-Dist: setuptools_scm; extra == "dev"
|
|
20
19
|
Requires-Dist: twine; extra == "dev"
|
|
21
20
|
|
|
22
21
|
# X-Auth
|
|
@@ -14,15 +14,14 @@ dependencies = [
|
|
|
14
14
|
"fastapi",
|
|
15
15
|
'pwdlib[argon2]',
|
|
16
16
|
"python-jose[cryptography]",
|
|
17
|
-
"xn-model"
|
|
17
|
+
"xn-model"
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
[project.optional-dependencies]
|
|
21
21
|
dev = [
|
|
22
22
|
"build",
|
|
23
23
|
"python-dotenv",
|
|
24
|
-
"
|
|
25
|
-
"twine",
|
|
24
|
+
"twine"
|
|
26
25
|
]
|
|
27
26
|
|
|
28
27
|
[project.urls]
|
|
@@ -55,7 +55,7 @@ class BearerSecurity(SecurityBase):
|
|
|
55
55
|
return None
|
|
56
56
|
if scheme.lower() != self.model.scheme:
|
|
57
57
|
if self.auto_error:
|
|
58
|
-
raise AuthException(reason=AuthFailReason.scheme, parent="
|
|
58
|
+
raise AuthException(reason=AuthFailReason.scheme, parent="Invaid scheme")
|
|
59
59
|
else:
|
|
60
60
|
return None
|
|
61
61
|
return credentials
|
|
@@ -63,9 +63,10 @@ class BearerSecurity(SecurityBase):
|
|
|
63
63
|
|
|
64
64
|
def on_error(_: HTTPConnection, exc: AuthException) -> Response:
|
|
65
65
|
hdr = {}
|
|
66
|
-
|
|
66
|
+
status = getattr(exc, "status_code", 401)
|
|
67
|
+
if status == 303 and "/login" in (r.path for r in _.app.routes):
|
|
67
68
|
hdr = {"Location": "/login"}
|
|
68
|
-
resp = Response(
|
|
69
|
+
resp = Response(exc.__repr__(), status_code=status, headers=hdr)
|
|
69
70
|
resp.delete_cookie(cookie_name)
|
|
70
71
|
return resp
|
|
71
72
|
|
|
@@ -6,18 +6,10 @@ from x_auth.enums import UserStatus, Role
|
|
|
6
6
|
|
|
7
7
|
class UserReg(BaseModel):
|
|
8
8
|
username: str
|
|
9
|
+
status: UserStatus = UserStatus.WAIT
|
|
10
|
+
role: Role = Role.READER
|
|
9
11
|
email: str | None = None
|
|
10
12
|
phone: int | None = None
|
|
11
|
-
role: Role = Role.READER
|
|
12
|
-
status: UserStatus = UserStatus.WAIT
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class UserUpdate(BaseModel):
|
|
16
|
-
username: str
|
|
17
|
-
status: UserStatus
|
|
18
|
-
email: str | None
|
|
19
|
-
phone: int | None
|
|
20
|
-
role: Role
|
|
21
13
|
|
|
22
14
|
|
|
23
15
|
class AuthUser(BaseModel, BaseUser):
|
|
@@ -29,7 +21,7 @@ class AuthUser(BaseModel, BaseUser):
|
|
|
29
21
|
@computed_field
|
|
30
22
|
@property
|
|
31
23
|
def is_authenticated(self) -> bool:
|
|
32
|
-
return self.status
|
|
24
|
+
return bool(self.status)
|
|
33
25
|
|
|
34
26
|
@computed_field
|
|
35
27
|
@property
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from datetime import timedelta
|
|
2
2
|
from tortoise.exceptions import IntegrityError, ConfigurationError
|
|
3
|
+
from starlette.authentication import AuthenticationBackend
|
|
4
|
+
from fastapi.routing import APIRoute
|
|
3
5
|
from x_model import FailReason
|
|
4
|
-
|
|
5
6
|
from x_auth.backend import AuthBackend
|
|
6
|
-
|
|
7
7
|
from x_auth.depend import Depend
|
|
8
8
|
from x_auth.enums import AuthFailReason
|
|
9
9
|
from x_auth import jwt_encode, HTTPException, AuthException, BearerSecurity
|
|
@@ -14,7 +14,13 @@ from x_auth.pydantic import AuthUser, UserReg, Token
|
|
|
14
14
|
class AuthRouter:
|
|
15
15
|
expires = timedelta(minutes=15)
|
|
16
16
|
|
|
17
|
-
def __init__(
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
secret: str,
|
|
20
|
+
db_user_model: type(User) = User,
|
|
21
|
+
backend: AuthenticationBackend = None,
|
|
22
|
+
scheme: BearerSecurity = BearerSecurity(),
|
|
23
|
+
):
|
|
18
24
|
self.depend = Depend(scheme)
|
|
19
25
|
self.secret = secret
|
|
20
26
|
self.db_user_model = db_user_model
|
|
@@ -35,7 +41,7 @@ class AuthRouter:
|
|
|
35
41
|
"reg": (self.reg, "POST"),
|
|
36
42
|
"refresh": (refresh, "GET"),
|
|
37
43
|
}
|
|
38
|
-
self.backend = AuthBackend(secret, scheme)
|
|
44
|
+
self.backend = backend or AuthBackend(secret, scheme)
|
|
39
45
|
|
|
40
46
|
# API ENDOINTS
|
|
41
47
|
def _user2tok(self, user: AuthUser) -> Token:
|
|
@@ -49,3 +55,16 @@ class AuthRouter:
|
|
|
49
55
|
except IntegrityError as e:
|
|
50
56
|
raise HTTPException(FailReason.body, e)
|
|
51
57
|
return self._user2tok(db_user.get_auth())
|
|
58
|
+
|
|
59
|
+
def get_routes(self) -> list[APIRoute]:
|
|
60
|
+
return [
|
|
61
|
+
APIRoute(
|
|
62
|
+
"/" + path,
|
|
63
|
+
func,
|
|
64
|
+
tags=["Auth"],
|
|
65
|
+
methods=[method],
|
|
66
|
+
name=path.title(),
|
|
67
|
+
operation_id=path,
|
|
68
|
+
)
|
|
69
|
+
for path, (func, method) in self.routes.items()
|
|
70
|
+
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: xn-auth
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Auth adapter for XN-Api framework
|
|
5
5
|
Author-email: Artemiev <mixartemev@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -16,7 +16,6 @@ Requires-Dist: xn-model
|
|
|
16
16
|
Provides-Extra: dev
|
|
17
17
|
Requires-Dist: build; extra == "dev"
|
|
18
18
|
Requires-Dist: python-dotenv; extra == "dev"
|
|
19
|
-
Requires-Dist: setuptools_scm; extra == "dev"
|
|
20
19
|
Requires-Dist: twine; extra == "dev"
|
|
21
20
|
|
|
22
21
|
# X-Auth
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|