pixelarraythirdparty 1.2.4__py3-none-any.whl → 1.2.5__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.
@@ -13,7 +13,7 @@ PixelArray 第三方微服务客户端
13
13
  - project: 项目管理模块
14
14
  """
15
15
 
16
- __version__ = "1.2.4"
16
+ __version__ = "1.2.5"
17
17
  __author__ = "Lu qi"
18
18
  __email__ = "qi.lu@pixelarrayai.com"
19
19
 
@@ -4,6 +4,7 @@ from .unified_login import (
4
4
  WechatLogin,
5
5
  GitHubLogin,
6
6
  DouyinLogin,
7
+ TiktokLogin,
7
8
  GitLabLogin,
8
9
  SMSLogin,
9
10
  EmailLogin,
@@ -15,6 +16,7 @@ __all__ = [
15
16
  "WechatLogin",
16
17
  "GitHubLogin",
17
18
  "DouyinLogin",
19
+ "TiktokLogin",
18
20
  "GitLabLogin",
19
21
  "SMSLogin",
20
22
  "EmailLogin",
@@ -10,7 +10,7 @@ class OAuth2Login(AsyncClient):
10
10
  """
11
11
  统一的 OAuth2 登录客户端基类
12
12
 
13
- 支持所有基于 OAuth2 的第三方登录(Google、微信、GitHub、GitLab、抖音等)
13
+ 支持所有基于 OAuth2 的第三方登录(Google、微信、GitHub、GitLab、抖音、TikTok等)
14
14
  通过配置不同的端点来支持不同的提供商
15
15
 
16
16
  使用示例:
@@ -60,6 +60,10 @@ class OAuth2Login(AsyncClient):
60
60
  "auth_url": "/api/unified-login/douyin/auth-url",
61
61
  "wait_login": "/api/unified-login/douyin/wait-login",
62
62
  },
63
+ "tiktok": {
64
+ "auth_url": "/api/unified-login/tiktok/auth-url",
65
+ "wait_login": "/api/unified-login/tiktok/wait-login",
66
+ },
63
67
  }
64
68
 
65
69
  def __init__(self, api_key: str, provider: str, login_type: Optional[str] = None):
@@ -68,7 +72,7 @@ class OAuth2Login(AsyncClient):
68
72
  初始化OAuth2登录客户端
69
73
  parameters:
70
74
  api_key(str): API密钥
71
- provider(str): 提供商名称,可选值:google, wechat, github, gitlab, douyin
75
+ provider(str): 提供商名称,可选值:google, wechat, github, gitlab, douyin, tiktok
72
76
  login_type(str, optional): 登录类型,仅对微信有效,可选值:desktop(PC端扫码), mobile(手机端)
73
77
  """
74
78
  super().__init__(api_key)
@@ -555,6 +559,85 @@ class DouyinLogin(AsyncClient):
555
559
  return {}, False
556
560
 
557
561
 
562
+ class TiktokLogin(AsyncClient):
563
+ """
564
+ TikTok OAuth2 登录客户端
565
+
566
+ 使用示例:
567
+ ```
568
+ # 服务端使用场景(推荐)
569
+ tiktok = TiktokLogin(api_key="your_api_key")
570
+ # 1. 获取授权URL
571
+ auth_data, success = await tiktok.get_auth_url()
572
+ if success:
573
+ auth_url = auth_data.get("auth_url")
574
+ state = auth_data.get("state")
575
+ # 将auth_url返回给前端,让用户点击授权
576
+ # 2. 等待登录结果(在服务端轮询)
577
+ user_info, success = await tiktok.wait_for_login(state, timeout=180)
578
+ print(user_info, success)
579
+ ```
580
+ """
581
+
582
+ def __init__(self, api_key: str):
583
+ super().__init__(api_key)
584
+
585
+ async def get_auth_url(self) -> Tuple[Optional[Dict[str, str]], bool]:
586
+ """
587
+ description:
588
+ 获取TikTok OAuth授权URL(公共方法,供服务端调用)
589
+
590
+ 服务端应该调用此方法获取授权URL,然后将URL返回给前端让用户点击授权。
591
+ 获取到state后,使用wait_for_login方法等待登录结果。
592
+ return:
593
+ auth_data(dict, optional): 授权数据字典,包含auth_url和state
594
+ success(bool): 是否成功
595
+ """
596
+ data, success = await self._request(
597
+ "POST", "/api/unified-login/tiktok/auth-url"
598
+ )
599
+ if not success:
600
+ return None, False
601
+ auth_url = data.get("auth_url")
602
+ if not auth_url:
603
+ return None, False
604
+ return data, True
605
+
606
+ async def wait_for_login(self, state: str, timeout: int = 180) -> Tuple[Dict, bool]:
607
+ """
608
+ description:
609
+ 等待TikTok登录结果,轮询检查登录状态(公共方法,供服务端调用)
610
+
611
+ 服务端在用户点击授权后,调用此方法轮询等待登录结果。
612
+ 此方法会持续轮询直到登录成功或超时。
613
+ parameters:
614
+ state(str): 登录状态标识,从get_auth_url返回的auth_data中获取
615
+ timeout(int, optional): 超时时间(秒),默认为180
616
+ return:
617
+ user_info(dict): 用户信息字典
618
+ success(bool): 是否成功
619
+ """
620
+ interval = 2
621
+ total_checks = max(1, timeout // interval) if timeout > 0 else 1
622
+
623
+ for _ in range(total_checks):
624
+ status, response = await self._request_raw(
625
+ "POST",
626
+ "/api/unified-login/tiktok/wait-login",
627
+ json={"state": state},
628
+ )
629
+
630
+ if status == 200 and response.get("success") is True:
631
+ return response.get("data", {}), True
632
+
633
+ if status in (400, 408):
634
+ break
635
+
636
+ await asyncio.sleep(interval)
637
+
638
+ return {}, False
639
+
640
+
558
641
  class GitLabLogin(AsyncClient):
559
642
  """
560
643
  GitLab OAuth2 登录客户端
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelarraythirdparty
3
- Version: 1.2.4
3
+ Version: 1.2.5
4
4
  Summary: PixelArray 第三方微服务客户端
5
5
  Author-email: Lu qi <qi.lu@pixelarrayai.com>
6
6
  License-Expression: MIT
@@ -1,4 +1,4 @@
1
- pixelarraythirdparty/__init__.py,sha256=ZPQ3uKaT_Scaf4p_JVcXXb90OdZ01QLEkXh57BGGnuY,582
1
+ pixelarraythirdparty/__init__.py,sha256=1wu0ftHnyYYWJvp1G00K3Y5GskiADKukHYRQIwrEGxA,582
2
2
  pixelarraythirdparty/client.py,sha256=Ym_IZ6cdoZJoMKW61ZRTfQ81-Hay5dpLTgExoANZwI4,3171
3
3
  pixelarraythirdparty/cron/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  pixelarraythirdparty/cron/cron.py,sha256=nv4e2hX_UkEJ-kbEARbInU2J6aREyYZ61dZ-4b9UWJI,3146
@@ -10,12 +10,12 @@ pixelarraythirdparty/product/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
10
10
  pixelarraythirdparty/product/product.py,sha256=5fgv2Ck860epYXxipY83vePziubCIlocFu43mGt_bhM,7497
11
11
  pixelarraythirdparty/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  pixelarraythirdparty/project/project.py,sha256=a8swjckyn4y3NlIx0-tMbcRwDY9woOijGi7lb1wN7Ok,2455
13
- pixelarraythirdparty/unified_login/__init__.py,sha256=tzy3nmRv-qZID-6kYRFarqQVrmkUsEI7D6de_PFu7Tg,327
14
- pixelarraythirdparty/unified_login/unified_login.py,sha256=chpB8Yj6yoPrh821LRe4BbDlLkK4Kn9n5X6FBiINUp0,29007
13
+ pixelarraythirdparty/unified_login/__init__.py,sha256=w1KfgvH7aplOUGcHMyo391Yls-Qw5pKIXrBv2npyes0,363
14
+ pixelarraythirdparty/unified_login/unified_login.py,sha256=HRx5qcuO2jb7UDdTkAOtrlbc6wZgo4BBcSglo9awAJM,31945
15
15
  pixelarraythirdparty/user/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  pixelarraythirdparty/user/user.py,sha256=SqufSAVMxQElz-NqtlOZs_dG7UtbuE-ygLAyml9oKpY,5761
17
- pixelarraythirdparty-1.2.4.dist-info/licenses/LICENSE,sha256=O-g1dUr0U50rSIvmWE9toiVkSgFpVt72_MHITbWvAqA,1067
18
- pixelarraythirdparty-1.2.4.dist-info/METADATA,sha256=2m92kvoPsCInrZsLpS094MxadQzGipcKcYtlEqa6GHY,993
19
- pixelarraythirdparty-1.2.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
- pixelarraythirdparty-1.2.4.dist-info/top_level.txt,sha256=dzG2Ut8j7noUqj_0ZQjcIDAeHYCh_9WtlxjAxtoyufo,21
21
- pixelarraythirdparty-1.2.4.dist-info/RECORD,,
17
+ pixelarraythirdparty-1.2.5.dist-info/licenses/LICENSE,sha256=O-g1dUr0U50rSIvmWE9toiVkSgFpVt72_MHITbWvAqA,1067
18
+ pixelarraythirdparty-1.2.5.dist-info/METADATA,sha256=3_xcei9sv8zaCaaY-5PRDkUWknZuIZl55znXfmDIK_A,993
19
+ pixelarraythirdparty-1.2.5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
20
+ pixelarraythirdparty-1.2.5.dist-info/top_level.txt,sha256=dzG2Ut8j7noUqj_0ZQjcIDAeHYCh_9WtlxjAxtoyufo,21
21
+ pixelarraythirdparty-1.2.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5