xn-auth 0.2.44__tar.gz → 0.2.46__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.4
2
2
  Name: xn-auth
3
- Version: 0.2.44
3
+ Version: 0.2.46
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -22,7 +22,7 @@ async def revoked_token_handler(token: Tok, _cn: ASGIConnection) -> bool:
22
22
 
23
23
 
24
24
  class Auth:
25
- def __init__(self, sec: str, user_model: type[User] = User, exc_paths: list[str] = None):
25
+ def __init__(self, sec: str, user_model: type[User] = User, exc_paths: list[str] = None, domain: str = ".xync.net"):
26
26
  self.jwt = JWTCookieAuth( # [AuthUser, Tok]
27
27
  retrieve_user_handler=retrieve_user_handler,
28
28
  revoked_token_handler=revoked_token_handler,
@@ -30,7 +30,7 @@ class Auth:
30
30
  authentication_middleware_class=JWTAuthMiddleware,
31
31
  token_secret=sec,
32
32
  token_cls=Tok,
33
- domain=".xync.net",
33
+ domain=domain,
34
34
  # endpoints excluded from authentication: (login and openAPI docs)
35
35
  exclude=["/schema", "/auth", "/public"] + (exc_paths or []),
36
36
  )
@@ -42,7 +42,7 @@ class Auth:
42
42
  identifier=str(db_user.id),
43
43
  token_extras={"role": db_user.role, "blocked": db_user.blocked},
44
44
  response_body=XyncUser.model_validate(
45
- {**user.model_dump(), "pub": db_user.pub and b64encode(db_user.pub)}
45
+ {**user.model_dump(), "xid": db_user.id, "pub": db_user.pub and b64encode(db_user.pub)}
46
46
  ),
47
47
  )
48
48
  res.cookies[0].httponly = False
@@ -54,6 +54,7 @@ class User(Model):
54
54
  blocked: bool = BooleanField(default=False)
55
55
  lang: Lang | None = IntEnumField(Lang, default=Lang.ru, null=True)
56
56
  role: Role = IntEnumField(Role, default=Role.READER)
57
+ prv = UniqBinaryField(unique=True, null=True) # len=32
57
58
  pub = UniqBinaryField(unique=True, null=True) # len=32
58
59
 
59
60
  app: BackwardOneToOneRelation["App"]
@@ -67,7 +68,7 @@ class User(Model):
67
68
  "last_name": u.last_name,
68
69
  "username_id": un.id,
69
70
  "lang": u.language_code and Lang[u.language_code],
70
- "pic": u.photo_url and u.photo_url.replace("https://t.me/i/userpic/320/", "")[:-4],
71
+ "pic": hasattr(u, "photo_url") and u.photo_url.replace("https://t.me/i/userpic/320/", "")[:-4],
71
72
  }
72
73
  )
73
74
  if blocked is not None:
@@ -9,6 +9,10 @@ from x_auth.enums import Role
9
9
 
10
10
 
11
11
  class Xs(Struct):
12
+ @classmethod
13
+ def dec_hook(cls, *args, **kwargs):
14
+ pass
15
+
12
16
  def dump(self, nones: bool = False) -> dict:
13
17
  return {k: v for k, v in to_builtins(self).items() if nones or v is not None}
14
18
 
@@ -18,7 +22,7 @@ class Xs(Struct):
18
22
  @classmethod
19
23
  def load(cls, obj, **kwargs) -> Self:
20
24
  dct = dict(obj)
21
- return convert({**dct, **kwargs}, cls) # , strict=False
25
+ return convert({**dct, **kwargs}, cls, dec_hook=cls.dec_hook) # , strict=False
22
26
 
23
27
 
24
28
  class AuthUser(Struct):
@@ -63,4 +67,5 @@ class TgUser(Xs):
63
67
 
64
68
 
65
69
  class XyncUser(WebAppUser):
70
+ xid: int
66
71
  pub: bytes | None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xn-auth
3
- Version: 0.2.44
3
+ Version: 0.2.46
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
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