pixelarraythirdparty 1.2.2__py3-none-any.whl → 1.2.3__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.
- pixelarraythirdparty/__init__.py +1 -1
- pixelarraythirdparty/unified_login/unified_login.py +223 -66
- {pixelarraythirdparty-1.2.2.dist-info → pixelarraythirdparty-1.2.3.dist-info}/METADATA +1 -1
- {pixelarraythirdparty-1.2.2.dist-info → pixelarraythirdparty-1.2.3.dist-info}/RECORD +7 -7
- {pixelarraythirdparty-1.2.2.dist-info → pixelarraythirdparty-1.2.3.dist-info}/WHEEL +0 -0
- {pixelarraythirdparty-1.2.2.dist-info → pixelarraythirdparty-1.2.3.dist-info}/licenses/LICENSE +0 -0
- {pixelarraythirdparty-1.2.2.dist-info → pixelarraythirdparty-1.2.3.dist-info}/top_level.txt +0 -0
pixelarraythirdparty/__init__.py
CHANGED
|
@@ -15,7 +15,21 @@ class OAuth2Login(AsyncClient):
|
|
|
15
15
|
|
|
16
16
|
使用示例:
|
|
17
17
|
```
|
|
18
|
-
#
|
|
18
|
+
# 服务端使用场景(推荐)
|
|
19
|
+
google = OAuth2Login(
|
|
20
|
+
api_key="your_api_key",
|
|
21
|
+
provider="google"
|
|
22
|
+
)
|
|
23
|
+
# 1. 获取授权URL
|
|
24
|
+
auth_data, success = await google.get_auth_url()
|
|
25
|
+
if success:
|
|
26
|
+
auth_url = auth_data.get("auth_url")
|
|
27
|
+
state = auth_data.get("state")
|
|
28
|
+
# 将auth_url返回给前端,让用户点击授权
|
|
29
|
+
# 2. 等待登录结果(在服务端轮询)
|
|
30
|
+
user_info, success = await google.wait_for_login(state, timeout=180)
|
|
31
|
+
|
|
32
|
+
# 测试场景(仅用于本地测试,会打开浏览器)
|
|
19
33
|
google = OAuth2Login(
|
|
20
34
|
api_key="your_api_key",
|
|
21
35
|
provider="google"
|
|
@@ -123,10 +137,13 @@ class OAuth2Login(AsyncClient):
|
|
|
123
137
|
)
|
|
124
138
|
return endpoint
|
|
125
139
|
|
|
126
|
-
async def
|
|
140
|
+
async def get_auth_url(self) -> Tuple[Optional[Dict[str, str]], bool]:
|
|
127
141
|
"""
|
|
128
142
|
description:
|
|
129
|
-
获取OAuth授权URL
|
|
143
|
+
获取OAuth授权URL(公共方法,供服务端调用)
|
|
144
|
+
|
|
145
|
+
服务端应该调用此方法获取授权URL,然后将URL返回给前端让用户点击授权。
|
|
146
|
+
获取到state后,使用wait_for_login方法等待登录结果。
|
|
130
147
|
return:
|
|
131
148
|
auth_data(dict, optional): 授权数据字典,包含auth_url和state
|
|
132
149
|
success(bool): 是否成功
|
|
@@ -161,15 +178,18 @@ class OAuth2Login(AsyncClient):
|
|
|
161
178
|
return None
|
|
162
179
|
return None
|
|
163
180
|
|
|
164
|
-
async def
|
|
165
|
-
self, state: str, timeout: int
|
|
181
|
+
async def wait_for_login(
|
|
182
|
+
self, state: str, timeout: int = 180
|
|
166
183
|
) -> Tuple[Dict, bool]:
|
|
167
184
|
"""
|
|
168
185
|
description:
|
|
169
|
-
|
|
186
|
+
等待登录结果,轮询检查登录状态(公共方法,供服务端调用)
|
|
187
|
+
|
|
188
|
+
服务端在用户点击授权后,调用此方法轮询等待登录结果。
|
|
189
|
+
此方法会持续轮询直到登录成功或超时。
|
|
170
190
|
parameters:
|
|
171
|
-
state(str):
|
|
172
|
-
timeout(int):
|
|
191
|
+
state(str): 登录状态标识,从get_auth_url返回的auth_data中获取
|
|
192
|
+
timeout(int, optional): 超时时间(秒),默认为180
|
|
173
193
|
return:
|
|
174
194
|
user_info(dict): 用户信息字典
|
|
175
195
|
success(bool): 是否成功
|
|
@@ -199,13 +219,16 @@ class OAuth2Login(AsyncClient):
|
|
|
199
219
|
"""
|
|
200
220
|
description:
|
|
201
221
|
仿 Supabase CLI 的一键登录流程:打开浏览器完成授权,终端端轮询等待登录结果
|
|
222
|
+
|
|
223
|
+
注意:此方法仅用于本地测试场景,会自动打开浏览器。
|
|
224
|
+
在生产环境的服务端场景中,应该使用get_auth_url和wait_for_login方法。
|
|
202
225
|
parameters:
|
|
203
226
|
timeout(int, optional): 等待用户完成授权的超时时间(秒),默认为180
|
|
204
227
|
return:
|
|
205
228
|
user_info(dict): 用户信息字典
|
|
206
229
|
success(bool): 是否成功
|
|
207
230
|
"""
|
|
208
|
-
auth_data, success = await self.
|
|
231
|
+
auth_data, success = await self.get_auth_url()
|
|
209
232
|
if not success or not auth_data:
|
|
210
233
|
return {}, False
|
|
211
234
|
|
|
@@ -217,7 +240,7 @@ class OAuth2Login(AsyncClient):
|
|
|
217
240
|
|
|
218
241
|
webbrowser.open(auth_url, new=2)
|
|
219
242
|
|
|
220
|
-
return await self.
|
|
243
|
+
return await self.wait_for_login(state, timeout)
|
|
221
244
|
|
|
222
245
|
async def refresh_access_token(self, refresh_token: str) -> Tuple[Dict, bool]:
|
|
223
246
|
"""
|
|
@@ -254,27 +277,42 @@ class GoogleLogin(AsyncClient):
|
|
|
254
277
|
|
|
255
278
|
使用示例:
|
|
256
279
|
```
|
|
280
|
+
# 服务端使用场景(推荐)
|
|
257
281
|
google = GoogleLogin(api_key="your_api_key")
|
|
258
|
-
|
|
282
|
+
# 1. 获取授权URL
|
|
283
|
+
auth_data, success = await google.get_auth_url()
|
|
259
284
|
if success:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
#
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
285
|
+
auth_url = auth_data.get("auth_url")
|
|
286
|
+
state = auth_data.get("state")
|
|
287
|
+
# 将auth_url返回给前端,让用户点击授权
|
|
288
|
+
# 2. 等待登录结果(在服务端轮询)
|
|
289
|
+
user_info, success = await google.wait_for_login(state, timeout=180)
|
|
290
|
+
if success:
|
|
291
|
+
access_token = user_info.get("access_token")
|
|
292
|
+
refresh_token = user_info.get("refresh_token")
|
|
293
|
+
|
|
294
|
+
# 使用refresh_token刷新access_token
|
|
295
|
+
if refresh_token:
|
|
296
|
+
token_data, success = await google.refresh_access_token(refresh_token)
|
|
297
|
+
if success:
|
|
298
|
+
new_access_token = token_data.get("access_token")
|
|
299
|
+
|
|
300
|
+
# 测试场景(仅用于本地测试,会打开浏览器)
|
|
301
|
+
google = GoogleLogin(api_key="your_api_key")
|
|
302
|
+
user_info, success = await google.login()
|
|
268
303
|
```
|
|
269
304
|
"""
|
|
270
305
|
|
|
271
306
|
def __init__(self, api_key: str):
|
|
272
307
|
super().__init__(api_key)
|
|
273
308
|
|
|
274
|
-
async def
|
|
309
|
+
async def get_auth_url(self) -> Tuple[Optional[Dict[str, str]], bool]:
|
|
275
310
|
"""
|
|
276
311
|
description:
|
|
277
|
-
获取Google OAuth授权URL
|
|
312
|
+
获取Google OAuth授权URL(公共方法,供服务端调用)
|
|
313
|
+
|
|
314
|
+
服务端应该调用此方法获取授权URL,然后将URL返回给前端让用户点击授权。
|
|
315
|
+
获取到state后,使用wait_for_login方法等待登录结果。
|
|
278
316
|
return:
|
|
279
317
|
auth_data(dict, optional): 授权数据字典,包含auth_url和state
|
|
280
318
|
success(bool): 是否成功
|
|
@@ -293,13 +331,16 @@ class GoogleLogin(AsyncClient):
|
|
|
293
331
|
"""
|
|
294
332
|
description:
|
|
295
333
|
仿 Supabase CLI 的一键登录流程:打开浏览器完成授权,终端端轮询等待登录结果
|
|
334
|
+
|
|
335
|
+
注意:此方法仅用于本地测试场景,会自动打开浏览器。
|
|
336
|
+
在生产环境的服务端场景中,应该使用get_auth_url和wait_for_login方法。
|
|
296
337
|
parameters:
|
|
297
338
|
timeout(int, optional): 等待用户完成授权的超时时间(秒),默认为180
|
|
298
339
|
return:
|
|
299
340
|
user_info(dict): 用户信息字典
|
|
300
341
|
success(bool): 是否成功
|
|
301
342
|
"""
|
|
302
|
-
auth_data, success = await self.
|
|
343
|
+
auth_data, success = await self.get_auth_url()
|
|
303
344
|
if not success or not auth_data:
|
|
304
345
|
return {}, False
|
|
305
346
|
|
|
@@ -311,7 +352,7 @@ class GoogleLogin(AsyncClient):
|
|
|
311
352
|
|
|
312
353
|
webbrowser.open(auth_url, new=2)
|
|
313
354
|
|
|
314
|
-
return await self.
|
|
355
|
+
return await self.wait_for_login(state, timeout)
|
|
315
356
|
|
|
316
357
|
def _extract_state(self, auth_url: Optional[str]) -> Optional[str]:
|
|
317
358
|
if not auth_url:
|
|
@@ -326,15 +367,18 @@ class GoogleLogin(AsyncClient):
|
|
|
326
367
|
return None
|
|
327
368
|
return None
|
|
328
369
|
|
|
329
|
-
async def
|
|
330
|
-
self, state: str, timeout: int
|
|
370
|
+
async def wait_for_login(
|
|
371
|
+
self, state: str, timeout: int = 180
|
|
331
372
|
) -> Tuple[Dict, bool]:
|
|
332
373
|
"""
|
|
333
374
|
description:
|
|
334
|
-
等待Google
|
|
375
|
+
等待Google登录结果,轮询检查登录状态(公共方法,供服务端调用)
|
|
376
|
+
|
|
377
|
+
服务端在用户点击授权后,调用此方法轮询等待登录结果。
|
|
378
|
+
此方法会持续轮询直到登录成功或超时。
|
|
335
379
|
parameters:
|
|
336
|
-
state(str):
|
|
337
|
-
timeout(int):
|
|
380
|
+
state(str): 登录状态标识,从get_auth_url返回的auth_data中获取
|
|
381
|
+
timeout(int, optional): 超时时间(秒),默认为180
|
|
338
382
|
return:
|
|
339
383
|
user_info(dict): 用户信息字典
|
|
340
384
|
success(bool): 是否成功
|
|
@@ -389,21 +433,42 @@ class WechatLogin(AsyncClient):
|
|
|
389
433
|
|
|
390
434
|
使用示例:
|
|
391
435
|
```
|
|
436
|
+
# 服务端使用场景(推荐)
|
|
392
437
|
wechat = WechatLogin(api_key="your_api_key")
|
|
393
438
|
# PC端扫码登录
|
|
394
|
-
|
|
439
|
+
auth_data, success = await wechat.get_auth_url(login_type="desktop")
|
|
440
|
+
if success:
|
|
441
|
+
auth_url = auth_data.get("auth_url")
|
|
442
|
+
state = auth_data.get("state")
|
|
443
|
+
# 将auth_url返回给前端,让用户扫码授权
|
|
444
|
+
# 等待登录结果
|
|
445
|
+
user_info, success = await wechat.wait_for_login(state, timeout=180, login_type="desktop")
|
|
446
|
+
|
|
395
447
|
# 微信公众号登录(手机端)
|
|
396
|
-
|
|
448
|
+
auth_data, success = await wechat.get_auth_url(login_type="mobile")
|
|
449
|
+
if success:
|
|
450
|
+
auth_url = auth_data.get("auth_url")
|
|
451
|
+
state = auth_data.get("state")
|
|
452
|
+
# 将auth_url返回给前端,让用户在微信内打开授权
|
|
453
|
+
# 等待登录结果
|
|
454
|
+
user_info, success = await wechat.wait_for_login(state, timeout=180, login_type="mobile")
|
|
455
|
+
|
|
456
|
+
# 测试场景(仅用于本地测试,会打开浏览器)
|
|
457
|
+
wechat = WechatLogin(api_key="your_api_key")
|
|
458
|
+
user_info, success = await wechat.login(login_type="desktop")
|
|
397
459
|
```
|
|
398
460
|
"""
|
|
399
461
|
|
|
400
462
|
def __init__(self, api_key: str):
|
|
401
463
|
super().__init__(api_key)
|
|
402
464
|
|
|
403
|
-
async def
|
|
465
|
+
async def get_auth_url(self, login_type: str = "desktop") -> Tuple[Optional[Dict[str, str]], bool]:
|
|
404
466
|
"""
|
|
405
467
|
description:
|
|
406
|
-
获取微信授权URL
|
|
468
|
+
获取微信授权URL(公共方法,供服务端调用)
|
|
469
|
+
|
|
470
|
+
服务端应该调用此方法获取授权URL,然后将URL返回给前端让用户点击授权。
|
|
471
|
+
获取到state后,使用wait_for_login方法等待登录结果。
|
|
407
472
|
parameters:
|
|
408
473
|
login_type(str, optional): 登录类型,desktop表示PC端扫码登录,mobile表示微信公众号登录,默认为desktop
|
|
409
474
|
return:
|
|
@@ -429,6 +494,9 @@ class WechatLogin(AsyncClient):
|
|
|
429
494
|
"""
|
|
430
495
|
description:
|
|
431
496
|
仿 Supabase CLI 的一键登录流程:打开浏览器完成授权,终端端轮询等待登录结果
|
|
497
|
+
|
|
498
|
+
注意:此方法仅用于本地测试场景,会自动打开浏览器。
|
|
499
|
+
在生产环境的服务端场景中,应该使用get_auth_url和wait_for_login方法。
|
|
432
500
|
parameters:
|
|
433
501
|
login_type(str, optional): 登录类型,desktop表示PC端扫码登录,mobile表示微信公众号登录,默认为desktop
|
|
434
502
|
timeout(int, optional): 等待用户完成授权的超时时间(秒),默认为180
|
|
@@ -436,7 +504,7 @@ class WechatLogin(AsyncClient):
|
|
|
436
504
|
user_info(dict): 用户信息字典
|
|
437
505
|
success(bool): 是否成功
|
|
438
506
|
"""
|
|
439
|
-
auth_data, success = await self.
|
|
507
|
+
auth_data, success = await self.get_auth_url(login_type)
|
|
440
508
|
if not success or not auth_data:
|
|
441
509
|
return {}, False
|
|
442
510
|
|
|
@@ -448,7 +516,7 @@ class WechatLogin(AsyncClient):
|
|
|
448
516
|
|
|
449
517
|
webbrowser.open(auth_url, new=2)
|
|
450
518
|
|
|
451
|
-
return await self.
|
|
519
|
+
return await self.wait_for_login(state, timeout, login_type)
|
|
452
520
|
|
|
453
521
|
def _extract_state(self, auth_url: Optional[str]) -> Optional[str]:
|
|
454
522
|
"""
|
|
@@ -471,15 +539,18 @@ class WechatLogin(AsyncClient):
|
|
|
471
539
|
return None
|
|
472
540
|
return None
|
|
473
541
|
|
|
474
|
-
async def
|
|
475
|
-
self, state: str, timeout: int, login_type: str = "desktop"
|
|
542
|
+
async def wait_for_login(
|
|
543
|
+
self, state: str, timeout: int = 180, login_type: str = "desktop"
|
|
476
544
|
) -> Tuple[Dict, bool]:
|
|
477
545
|
"""
|
|
478
546
|
description:
|
|
479
|
-
|
|
547
|
+
等待微信登录结果,轮询检查登录状态(公共方法,供服务端调用)
|
|
548
|
+
|
|
549
|
+
服务端在用户点击授权后,调用此方法轮询等待登录结果。
|
|
550
|
+
此方法会持续轮询直到登录成功或超时。
|
|
480
551
|
parameters:
|
|
481
|
-
state(str):
|
|
482
|
-
timeout(int):
|
|
552
|
+
state(str): 登录状态标识,从get_auth_url返回的auth_data中获取
|
|
553
|
+
timeout(int, optional): 超时时间(秒),默认为180
|
|
483
554
|
login_type(str, optional): 登录类型,desktop表示PC端扫码登录,mobile表示微信公众号登录,默认为desktop
|
|
484
555
|
return:
|
|
485
556
|
user_info(dict): 用户信息字典
|
|
@@ -518,6 +589,18 @@ class GitHubLogin(AsyncClient):
|
|
|
518
589
|
|
|
519
590
|
使用示例:
|
|
520
591
|
```
|
|
592
|
+
# 服务端使用场景(推荐)
|
|
593
|
+
github = GitHubLogin(api_key="your_api_key")
|
|
594
|
+
# 1. 获取授权URL
|
|
595
|
+
auth_data, success = await github.get_auth_url()
|
|
596
|
+
if success:
|
|
597
|
+
auth_url = auth_data.get("auth_url")
|
|
598
|
+
state = auth_data.get("state")
|
|
599
|
+
# 将auth_url返回给前端,让用户点击授权
|
|
600
|
+
# 2. 等待登录结果(在服务端轮询)
|
|
601
|
+
user_info, success = await github.wait_for_login(state, timeout=180)
|
|
602
|
+
|
|
603
|
+
# 测试场景(仅用于本地测试,会打开浏览器)
|
|
521
604
|
github = GitHubLogin(api_key="your_api_key")
|
|
522
605
|
user_info, success = await github.login()
|
|
523
606
|
```
|
|
@@ -526,10 +609,13 @@ class GitHubLogin(AsyncClient):
|
|
|
526
609
|
def __init__(self, api_key: str):
|
|
527
610
|
super().__init__(api_key)
|
|
528
611
|
|
|
529
|
-
async def
|
|
612
|
+
async def get_auth_url(self) -> Tuple[Optional[Dict[str, str]], bool]:
|
|
530
613
|
"""
|
|
531
614
|
description:
|
|
532
|
-
获取GitHub OAuth授权URL
|
|
615
|
+
获取GitHub OAuth授权URL(公共方法,供服务端调用)
|
|
616
|
+
|
|
617
|
+
服务端应该调用此方法获取授权URL,然后将URL返回给前端让用户点击授权。
|
|
618
|
+
获取到state后,使用wait_for_login方法等待登录结果。
|
|
533
619
|
return:
|
|
534
620
|
auth_data(dict, optional): 授权数据字典,包含auth_url和state
|
|
535
621
|
success(bool): 是否成功
|
|
@@ -548,13 +634,16 @@ class GitHubLogin(AsyncClient):
|
|
|
548
634
|
"""
|
|
549
635
|
description:
|
|
550
636
|
仿 Supabase CLI 的一键登录流程:打开浏览器完成授权,终端端轮询等待登录结果
|
|
637
|
+
|
|
638
|
+
注意:此方法仅用于本地测试场景,会自动打开浏览器。
|
|
639
|
+
在生产环境的服务端场景中,应该使用get_auth_url和wait_for_login方法。
|
|
551
640
|
parameters:
|
|
552
641
|
timeout(int, optional): 等待用户完成授权的超时时间(秒),默认为180
|
|
553
642
|
return:
|
|
554
643
|
user_info(dict): 用户信息字典
|
|
555
644
|
success(bool): 是否成功
|
|
556
645
|
"""
|
|
557
|
-
auth_data, success = await self.
|
|
646
|
+
auth_data, success = await self.get_auth_url()
|
|
558
647
|
if not success or not auth_data:
|
|
559
648
|
return {}, False
|
|
560
649
|
|
|
@@ -566,7 +655,7 @@ class GitHubLogin(AsyncClient):
|
|
|
566
655
|
|
|
567
656
|
webbrowser.open(auth_url, new=2)
|
|
568
657
|
|
|
569
|
-
return await self.
|
|
658
|
+
return await self.wait_for_login(state, timeout)
|
|
570
659
|
|
|
571
660
|
def _extract_state(self, auth_url: Optional[str]) -> Optional[str]:
|
|
572
661
|
"""
|
|
@@ -589,15 +678,18 @@ class GitHubLogin(AsyncClient):
|
|
|
589
678
|
return None
|
|
590
679
|
return None
|
|
591
680
|
|
|
592
|
-
async def
|
|
593
|
-
self, state: str, timeout: int
|
|
681
|
+
async def wait_for_login(
|
|
682
|
+
self, state: str, timeout: int = 180
|
|
594
683
|
) -> Tuple[Dict, bool]:
|
|
595
684
|
"""
|
|
596
685
|
description:
|
|
597
|
-
等待GitHub
|
|
686
|
+
等待GitHub登录结果,轮询检查登录状态(公共方法,供服务端调用)
|
|
687
|
+
|
|
688
|
+
服务端在用户点击授权后,调用此方法轮询等待登录结果。
|
|
689
|
+
此方法会持续轮询直到登录成功或超时。
|
|
598
690
|
parameters:
|
|
599
|
-
state(str):
|
|
600
|
-
timeout(int):
|
|
691
|
+
state(str): 登录状态标识,从get_auth_url返回的auth_data中获取
|
|
692
|
+
timeout(int, optional): 超时时间(秒),默认为180
|
|
601
693
|
return:
|
|
602
694
|
user_info(dict): 用户信息字典
|
|
603
695
|
success(bool): 是否成功
|
|
@@ -629,6 +721,18 @@ class DouyinLogin(AsyncClient):
|
|
|
629
721
|
|
|
630
722
|
使用示例:
|
|
631
723
|
```
|
|
724
|
+
# 服务端使用场景(推荐)
|
|
725
|
+
douyin = DouyinLogin(api_key="your_api_key")
|
|
726
|
+
# 1. 获取授权URL
|
|
727
|
+
auth_data, success = await douyin.get_auth_url()
|
|
728
|
+
if success:
|
|
729
|
+
auth_url = auth_data.get("auth_url")
|
|
730
|
+
state = auth_data.get("state")
|
|
731
|
+
# 将auth_url返回给前端,让用户点击授权
|
|
732
|
+
# 2. 等待登录结果(在服务端轮询)
|
|
733
|
+
user_info, success = await douyin.wait_for_login(state, timeout=180)
|
|
734
|
+
|
|
735
|
+
# 测试场景(仅用于本地测试,会打开浏览器)
|
|
632
736
|
douyin = DouyinLogin(api_key="your_api_key")
|
|
633
737
|
user_info, success = await douyin.login()
|
|
634
738
|
```
|
|
@@ -637,10 +741,13 @@ class DouyinLogin(AsyncClient):
|
|
|
637
741
|
def __init__(self, api_key: str):
|
|
638
742
|
super().__init__(api_key)
|
|
639
743
|
|
|
640
|
-
async def
|
|
744
|
+
async def get_auth_url(self) -> Tuple[Optional[Dict[str, str]], bool]:
|
|
641
745
|
"""
|
|
642
746
|
description:
|
|
643
|
-
获取抖音OAuth授权URL
|
|
747
|
+
获取抖音OAuth授权URL(公共方法,供服务端调用)
|
|
748
|
+
|
|
749
|
+
服务端应该调用此方法获取授权URL,然后将URL返回给前端让用户点击授权。
|
|
750
|
+
获取到state后,使用wait_for_login方法等待登录结果。
|
|
644
751
|
return:
|
|
645
752
|
auth_data(dict, optional): 授权数据字典,包含auth_url和state
|
|
646
753
|
success(bool): 是否成功
|
|
@@ -659,13 +766,16 @@ class DouyinLogin(AsyncClient):
|
|
|
659
766
|
"""
|
|
660
767
|
description:
|
|
661
768
|
仿 Supabase CLI 的一键登录流程:打开浏览器完成授权,终端端轮询等待登录结果
|
|
769
|
+
|
|
770
|
+
注意:此方法仅用于本地测试场景,会自动打开浏览器。
|
|
771
|
+
在生产环境的服务端场景中,应该使用get_auth_url和wait_for_login方法。
|
|
662
772
|
parameters:
|
|
663
773
|
timeout(int, optional): 等待用户完成授权的超时时间(秒),默认为180
|
|
664
774
|
return:
|
|
665
775
|
user_info(dict): 用户信息字典
|
|
666
776
|
success(bool): 是否成功
|
|
667
777
|
"""
|
|
668
|
-
auth_data, success = await self.
|
|
778
|
+
auth_data, success = await self.get_auth_url()
|
|
669
779
|
if not success or not auth_data:
|
|
670
780
|
return {}, False
|
|
671
781
|
|
|
@@ -677,7 +787,7 @@ class DouyinLogin(AsyncClient):
|
|
|
677
787
|
|
|
678
788
|
webbrowser.open(auth_url, new=2)
|
|
679
789
|
|
|
680
|
-
return await self.
|
|
790
|
+
return await self.wait_for_login(state, timeout)
|
|
681
791
|
|
|
682
792
|
def _extract_state(self, auth_url: Optional[str]) -> Optional[str]:
|
|
683
793
|
"""
|
|
@@ -700,15 +810,18 @@ class DouyinLogin(AsyncClient):
|
|
|
700
810
|
return None
|
|
701
811
|
return None
|
|
702
812
|
|
|
703
|
-
async def
|
|
704
|
-
self, state: str, timeout: int
|
|
813
|
+
async def wait_for_login(
|
|
814
|
+
self, state: str, timeout: int = 180
|
|
705
815
|
) -> Tuple[Dict, bool]:
|
|
706
816
|
"""
|
|
707
817
|
description:
|
|
708
|
-
|
|
818
|
+
等待抖音登录结果,轮询检查登录状态(公共方法,供服务端调用)
|
|
819
|
+
|
|
820
|
+
服务端在用户点击授权后,调用此方法轮询等待登录结果。
|
|
821
|
+
此方法会持续轮询直到登录成功或超时。
|
|
709
822
|
parameters:
|
|
710
|
-
state(str):
|
|
711
|
-
timeout(int):
|
|
823
|
+
state(str): 登录状态标识,从get_auth_url返回的auth_data中获取
|
|
824
|
+
timeout(int, optional): 超时时间(秒),默认为180
|
|
712
825
|
return:
|
|
713
826
|
user_info(dict): 用户信息字典
|
|
714
827
|
success(bool): 是否成功
|
|
@@ -740,6 +853,21 @@ class GitLabLogin(AsyncClient):
|
|
|
740
853
|
|
|
741
854
|
使用示例:
|
|
742
855
|
```
|
|
856
|
+
# 服务端使用场景(推荐)
|
|
857
|
+
gitlab = GitLabLogin(api_key="your_api_key")
|
|
858
|
+
# 1. 获取授权URL
|
|
859
|
+
auth_data, success = await gitlab.get_auth_url()
|
|
860
|
+
if success:
|
|
861
|
+
auth_url = auth_data.get("auth_url")
|
|
862
|
+
state = auth_data.get("state")
|
|
863
|
+
# 将auth_url返回给前端,让用户点击授权
|
|
864
|
+
# 2. 等待登录结果(在服务端轮询)
|
|
865
|
+
user_info, success = await gitlab.wait_for_login(state, timeout=180)
|
|
866
|
+
if success and user_info.get("refresh_token"):
|
|
867
|
+
# 使用refresh_token刷新access_token
|
|
868
|
+
token_data, success = await gitlab.refresh_access_token(user_info.get("refresh_token"))
|
|
869
|
+
|
|
870
|
+
# 测试场景(仅用于本地测试,会打开浏览器)
|
|
743
871
|
gitlab = GitLabLogin(api_key="your_api_key")
|
|
744
872
|
user_info, success = await gitlab.login()
|
|
745
873
|
```
|
|
@@ -748,7 +876,17 @@ class GitLabLogin(AsyncClient):
|
|
|
748
876
|
def __init__(self, api_key: str):
|
|
749
877
|
super().__init__(api_key)
|
|
750
878
|
|
|
751
|
-
async def
|
|
879
|
+
async def get_auth_url(self) -> Tuple[Optional[Dict[str, str]], bool]:
|
|
880
|
+
"""
|
|
881
|
+
description:
|
|
882
|
+
获取GitLab OAuth授权URL(公共方法,供服务端调用)
|
|
883
|
+
|
|
884
|
+
服务端应该调用此方法获取授权URL,然后将URL返回给前端让用户点击授权。
|
|
885
|
+
获取到state后,使用wait_for_login方法等待登录结果。
|
|
886
|
+
return:
|
|
887
|
+
auth_data(dict, optional): 授权数据字典,包含auth_url和state
|
|
888
|
+
success(bool): 是否成功
|
|
889
|
+
"""
|
|
752
890
|
data, success = await self._request(
|
|
753
891
|
"POST", "/api/unified-login/gitlab/auth-url"
|
|
754
892
|
)
|
|
@@ -761,12 +899,18 @@ class GitLabLogin(AsyncClient):
|
|
|
761
899
|
|
|
762
900
|
async def login(self, timeout: int = 180) -> Tuple[Dict, bool]:
|
|
763
901
|
"""
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
902
|
+
description:
|
|
903
|
+
仿 Supabase CLI 的一键登录流程:打开浏览器完成授权,终端端轮询等待登录结果
|
|
904
|
+
|
|
905
|
+
注意:此方法仅用于本地测试场景,会自动打开浏览器。
|
|
906
|
+
在生产环境的服务端场景中,应该使用get_auth_url和wait_for_login方法。
|
|
907
|
+
parameters:
|
|
908
|
+
timeout(int, optional): 等待用户完成授权的超时时间(秒),默认为180
|
|
909
|
+
return:
|
|
910
|
+
user_info(dict): 用户信息字典
|
|
911
|
+
success(bool): 是否成功
|
|
768
912
|
"""
|
|
769
|
-
auth_data, success = await self.
|
|
913
|
+
auth_data, success = await self.get_auth_url()
|
|
770
914
|
if not success or not auth_data:
|
|
771
915
|
return {}, False
|
|
772
916
|
|
|
@@ -778,7 +922,7 @@ class GitLabLogin(AsyncClient):
|
|
|
778
922
|
|
|
779
923
|
webbrowser.open(auth_url, new=2)
|
|
780
924
|
|
|
781
|
-
return await self.
|
|
925
|
+
return await self.wait_for_login(state, timeout)
|
|
782
926
|
|
|
783
927
|
def _extract_state(self, auth_url: Optional[str]) -> Optional[str]:
|
|
784
928
|
if not auth_url:
|
|
@@ -793,9 +937,22 @@ class GitLabLogin(AsyncClient):
|
|
|
793
937
|
return None
|
|
794
938
|
return None
|
|
795
939
|
|
|
796
|
-
async def
|
|
797
|
-
self, state: str, timeout: int
|
|
940
|
+
async def wait_for_login(
|
|
941
|
+
self, state: str, timeout: int = 180
|
|
798
942
|
) -> Tuple[Dict, bool]:
|
|
943
|
+
"""
|
|
944
|
+
description:
|
|
945
|
+
等待GitLab登录结果,轮询检查登录状态(公共方法,供服务端调用)
|
|
946
|
+
|
|
947
|
+
服务端在用户点击授权后,调用此方法轮询等待登录结果。
|
|
948
|
+
此方法会持续轮询直到登录成功或超时。
|
|
949
|
+
parameters:
|
|
950
|
+
state(str): 登录状态标识,从get_auth_url返回的auth_data中获取
|
|
951
|
+
timeout(int, optional): 超时时间(秒),默认为180
|
|
952
|
+
return:
|
|
953
|
+
user_info(dict): 用户信息字典
|
|
954
|
+
success(bool): 是否成功
|
|
955
|
+
"""
|
|
799
956
|
interval = 2
|
|
800
957
|
total_checks = max(1, timeout // interval) if timeout > 0 else 1
|
|
801
958
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
pixelarraythirdparty/__init__.py,sha256=
|
|
1
|
+
pixelarraythirdparty/__init__.py,sha256=zQsr327IH9uZgfbsXIpwvP6B_KJltOQFfaWJ5NqGHAo,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
|
|
@@ -11,11 +11,11 @@ pixelarraythirdparty/product/product.py,sha256=5fgv2Ck860epYXxipY83vePziubCIlocF
|
|
|
11
11
|
pixelarraythirdparty/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
pixelarraythirdparty/project/project.py,sha256=a8swjckyn4y3NlIx0-tMbcRwDY9woOijGi7lb1wN7Ok,2455
|
|
13
13
|
pixelarraythirdparty/unified_login/__init__.py,sha256=tzy3nmRv-qZID-6kYRFarqQVrmkUsEI7D6de_PFu7Tg,327
|
|
14
|
-
pixelarraythirdparty/unified_login/unified_login.py,sha256=
|
|
14
|
+
pixelarraythirdparty/unified_login/unified_login.py,sha256=A1Sl0g0s9MrBdSmrFiui2r15sA0Xd17iTQIUfJsZEFQ,41483
|
|
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.
|
|
18
|
-
pixelarraythirdparty-1.2.
|
|
19
|
-
pixelarraythirdparty-1.2.
|
|
20
|
-
pixelarraythirdparty-1.2.
|
|
21
|
-
pixelarraythirdparty-1.2.
|
|
17
|
+
pixelarraythirdparty-1.2.3.dist-info/licenses/LICENSE,sha256=O-g1dUr0U50rSIvmWE9toiVkSgFpVt72_MHITbWvAqA,1067
|
|
18
|
+
pixelarraythirdparty-1.2.3.dist-info/METADATA,sha256=_TNjpH-NiF7st_CYAxM9Gz8LWs01m-Prlzjw7vZ4708,993
|
|
19
|
+
pixelarraythirdparty-1.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
20
|
+
pixelarraythirdparty-1.2.3.dist-info/top_level.txt,sha256=dzG2Ut8j7noUqj_0ZQjcIDAeHYCh_9WtlxjAxtoyufo,21
|
|
21
|
+
pixelarraythirdparty-1.2.3.dist-info/RECORD,,
|
|
File without changes
|
{pixelarraythirdparty-1.2.2.dist-info → pixelarraythirdparty-1.2.3.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|