xn-auth 0.2.40__py3-none-any.whl → 0.2.41__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.
x_auth/controller.py CHANGED
@@ -1,3 +1,4 @@
1
+ from base64 import b64encode
1
2
  from datetime import timedelta
2
3
 
3
4
  from aiogram.utils.auth_widget import check_signature
@@ -9,7 +10,7 @@ from litestar.security.jwt import JWTCookieAuth
9
10
 
10
11
  from x_auth.middleware import JWTAuthMiddleware, Tok
11
12
  from x_auth.models import User
12
- from x_auth.types import AuthUser, TgUser
13
+ from x_auth.types import AuthUser, TgUser, XyncUser
13
14
 
14
15
 
15
16
  async def retrieve_user_handler(token: Tok, _cn: ASGIConnection) -> AuthUser:
@@ -34,31 +35,31 @@ class Auth:
34
35
  exclude=["/schema", "/auth", "/public"] + (exc_paths or []),
35
36
  )
36
37
 
37
- async def user_proc(user: WebAppUser) -> Response[WebAppUser]:
38
+ async def user_proc(user: WebAppUser) -> Response[XyncUser]:
38
39
  user_in = await user_model.tg2in(user)
39
40
  db_user, cr = await user_model.update_or_create(**user_in.df_unq()) # on login: update user in db from tg
40
41
  res = self.jwt.login(
41
42
  identifier=str(db_user.id),
42
43
  token_extras={"role": db_user.role, "blocked": db_user.blocked},
43
- response_body=user,
44
+ response_body=XyncUser.model_validate({**user.model_dump(), "pub": b64encode(db_user.pub)}),
44
45
  )
45
46
  res.cookies[0].httponly = False
46
47
  return res
47
48
 
48
49
  # login for api endpoint
49
50
  @post("/auth/twa", tags=["Auth"], description="Gen JWToken from tg login widget")
50
- async def twa(data: TgUser) -> Response[WebAppUser]: # widget
51
+ async def twa(data: TgUser) -> Response[XyncUser]: # widget
51
52
  dct = data.dump()
52
53
  if not check_signature(self.jwt.token_secret, dct.pop("hash"), **dct):
53
54
  raise NotAuthorizedException("Tg login widget data invalid")
54
55
  return await user_proc(WebAppUser(**dct))
55
56
 
56
57
  @post("/auth/tma", tags=["Auth"], description="Gen JWToken from tg initData")
57
- async def tma(tid: str) -> Response[WebAppUser]:
58
+ async def tma(tid: str) -> Response[XyncUser]:
58
59
  try:
59
60
  twaid: WebAppInitData = safe_parse_webapp_init_data(self.jwt.token_secret, tid)
60
- except ValueError:
61
- raise NotAuthorizedException(detail="Tg Initdata invalid")
61
+ except ValueError as e:
62
+ raise NotAuthorizedException(detail=f"Tg Initdata invalid {e}")
62
63
  return await user_proc(twaid.user)
63
64
 
64
65
  self.tma_handler = tma
x_auth/models.py CHANGED
@@ -35,6 +35,10 @@ from x_model.types import BaseUpd
35
35
  from x_auth.enums import Lang, Role, PeerType
36
36
 
37
37
 
38
+ class UniqBinaryField(BinaryField):
39
+ indexable = True
40
+
41
+
38
42
  class Username(TortModel):
39
43
  id: int = BigIntField(True, description="tg_id")
40
44
  username: str = CharField(127, null=True)
@@ -54,6 +58,8 @@ class User(Model):
54
58
  blocked: bool = BooleanField(default=False)
55
59
  lang: Lang | None = IntEnumField(Lang, default=Lang.ru, null=True)
56
60
  role: Role = IntEnumField(Role, default=Role.READER)
61
+ # prv = BinaryField(null=True) # len=32
62
+ pub = UniqBinaryField(unique=True, null=True) # len=32
57
63
 
58
64
  app: BackwardOneToOneRelation["App"]
59
65
 
x_auth/types.py CHANGED
@@ -2,6 +2,7 @@ from datetime import datetime
2
2
  from json import dumps
3
3
  from typing import Literal, Self
4
4
 
5
+ from aiogram.utils.web_app import WebAppUser
5
6
  from msgspec import Struct, to_builtins, convert
6
7
 
7
8
  from x_auth.enums import Role
@@ -59,3 +60,7 @@ class TgUser(Xs):
59
60
  username: str | None = None
60
61
  photo_url: str | None = None
61
62
  last_name: str | None = None
63
+
64
+
65
+ class XyncUser(WebAppUser):
66
+ pub: bytes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xn-auth
3
- Version: 0.2.40
3
+ Version: 0.2.41
4
4
  Summary: Auth adapter for XN-Api framework
5
5
  Author-email: Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -0,0 +1,10 @@
1
+ x_auth/controller.py,sha256=KGbXT-hX7Rp6eYZJGx_-ioAr3As73bbKjPhow41c1SE,2973
2
+ x_auth/enums.py,sha256=l4NTYsA-h0gyOp4PUe40Lb8LKoA94zL6EDkCmoGmBL0,732
3
+ x_auth/exceptions.py,sha256=2B4okJxhPyNqTJXlSTfblJUQJ60bLGXdgJIu6ue7S6w,162
4
+ x_auth/middleware.py,sha256=JfssQomDv0J_69GfS2a_2_uyRzs26zSY6IW1Vk7m8K0,2900
5
+ x_auth/models.py,sha256=kDk0je7f2TcfRrnCeTbB99ERBJmDaxGGjvIm53BIaYM,8996
6
+ x_auth/types.py,sha256=GTjNOm7XkyYDCdIaqByP2LzHnwCJRkWGOwdc4tVWFy0,1400
7
+ xn_auth-0.2.41.dist-info/METADATA,sha256=lPj2C37gFR3GN2b1xvIMxBzWbyU6KtTurQfNc3QBcTU,823
8
+ xn_auth-0.2.41.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ xn_auth-0.2.41.dist-info/top_level.txt,sha256=ydMDkzxgQPtW-E_MNDfUAroAFZvWSqU-x_kZSA7NSFo,7
10
+ xn_auth-0.2.41.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- x_auth/controller.py,sha256=8OVENJa5rUHui-8qswKBs2wYnU_PzQ74cDneszehcxo,2857
2
- x_auth/enums.py,sha256=l4NTYsA-h0gyOp4PUe40Lb8LKoA94zL6EDkCmoGmBL0,732
3
- x_auth/exceptions.py,sha256=2B4okJxhPyNqTJXlSTfblJUQJ60bLGXdgJIu6ue7S6w,162
4
- x_auth/middleware.py,sha256=JfssQomDv0J_69GfS2a_2_uyRzs26zSY6IW1Vk7m8K0,2900
5
- x_auth/models.py,sha256=m_7ANZMcuxRAW56dgGt86r843Wdib436xV-_e4CBLZ0,8832
6
- x_auth/types.py,sha256=zojizO58op_BUFvmxSaOtNoPB_liBCY3x3Ff80bgBMo,1310
7
- xn_auth-0.2.40.dist-info/METADATA,sha256=fKBWmd-GVj257JtxRFmPlvdRrRDtA20P3vyq6ZpdIIw,823
8
- xn_auth-0.2.40.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- xn_auth-0.2.40.dist-info/top_level.txt,sha256=ydMDkzxgQPtW-E_MNDfUAroAFZvWSqU-x_kZSA7NSFo,7
10
- xn_auth-0.2.40.dist-info/RECORD,,