xn-auth 0.2.2__tar.gz → 0.2.2.dev2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xn-auth
3
- Version: 0.2.2
3
+ Version: 0.2.2.dev2
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -16,6 +16,7 @@ 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"
19
20
  Requires-Dist: twine; extra == "dev"
20
21
 
21
22
  # X-Auth
@@ -14,14 +14,15 @@ 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
- "twine"
24
+ "setuptools_scm",
25
+ "twine",
25
26
  ]
26
27
 
27
28
  [project.urls]
@@ -1,5 +1,7 @@
1
+ import logging
1
2
  from datetime import timedelta
2
3
 
4
+ from fastapi import HTTPException as BaseHTTPException
3
5
  from fastapi.openapi.models import HTTPBase, SecuritySchemeType
4
6
  from fastapi.security.base import SecurityBase
5
7
  from fastapi.security.utils import get_authorization_scheme_param
@@ -11,14 +13,26 @@ from starlette.authentication import AuthenticationError
11
13
  from starlette.requests import HTTPConnection
12
14
  from starlette.responses import Response
13
15
  from tortoise.timezone import now
14
- from x_model import HTTPException
15
16
 
16
- from x_auth.enums import AuthFailReason
17
+ from x_auth.enums import FailReason, AuthFailReason
17
18
  from x_auth.pydantic import AuthUser
18
19
 
19
20
  cookie_name = "access_token"
20
21
 
21
22
 
23
+ class HTTPException(BaseHTTPException):
24
+ def __init__(
25
+ self,
26
+ reason: FailReason | AuthFailReason,
27
+ parent: Exception | str = None,
28
+ status_: status = status.HTTP_400_BAD_REQUEST,
29
+ hdrs: dict = None,
30
+ ) -> None:
31
+ detail = f"{reason.name}{f': {parent}' if parent else ''}"
32
+ logging.error(detail)
33
+ super().__init__(status_, detail, hdrs)
34
+
35
+
22
36
  class AuthException(HTTPException, AuthenticationError):
23
37
  def __init__(
24
38
  self,
@@ -25,6 +25,14 @@ class Role(IntEnum):
25
25
  return [scope.name for scope in Scope if self.value & scope.value]
26
26
 
27
27
 
28
+ class FailReason(IntEnum):
29
+ path = 8
30
+ query = 9
31
+ body = 10
32
+ method = 11
33
+ protocol = 12
34
+
35
+
28
36
  class AuthFailReason(IntEnum):
29
37
  no_token = 0
30
38
  username = 1
@@ -1,6 +1,6 @@
1
1
  from tortoise import fields
2
2
  from x_auth.pydantic import AuthUser
3
- from x_model.models import Model as BaseModel, TsTrait
3
+ from x_model.model import Model as BaseModel, TsTrait
4
4
 
5
5
  from x_auth.enums import UserStatus, Role, Scope
6
6
 
@@ -1,13 +1,11 @@
1
1
  from datetime import timedelta
2
2
  from tortoise.exceptions import IntegrityError, ConfigurationError
3
- from x_model import FailReason
4
-
5
3
  from x_auth.backend import AuthBackend
6
4
 
7
5
  from x_auth.depend import Depend
8
- from x_auth.enums import AuthFailReason
6
+ from x_auth.enums import FailReason, AuthFailReason
9
7
  from x_auth import jwt_encode, HTTPException, AuthException, BearerSecurity
10
- from x_auth.models import User
8
+ from x_auth.model import User
11
9
  from x_auth.pydantic import AuthUser, UserReg, Token
12
10
 
13
11
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xn-auth
3
- Version: 0.2.2
3
+ Version: 0.2.2.dev2
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -16,6 +16,7 @@ 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"
19
20
  Requires-Dist: twine; extra == "dev"
20
21
 
21
22
  # X-Auth
@@ -8,7 +8,7 @@ x_auth/__init__.py
8
8
  x_auth/backend.py
9
9
  x_auth/depend.py
10
10
  x_auth/enums.py
11
- x_auth/models.py
11
+ x_auth/model.py
12
12
  x_auth/pydantic.py
13
13
  x_auth/router.py
14
14
  xn_auth.egg-info/PKG-INFO
@@ -6,4 +6,5 @@ xn-model
6
6
  [dev]
7
7
  build
8
8
  python-dotenv
9
+ setuptools_scm
9
10
  twine
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes