feat(s2a_service): Add pure API authorization mode without browser
- Add S2A_API_MODE configuration option to enable browser-less authorization - Implement S2AApiAuthorizer class using curl_cffi for browser fingerprint simulation - Add Sentinel PoW (Proof of Work) solver with FNV-1a hashing algorithm - Implement OAuth flow via direct API calls instead of browser automation - Add s2a_api_authorize() function to handle email/password authentication - Support proxy configuration for API requests - Add requirements token generation for API authentication - Update browser_automation.py to check S2A_API_MODE and route to API or browser flow - Update config.py to load S2A_API_MODE from configuration - Add api_mode option to config.toml.example with documentation - Improves performance and stability by eliminating browser overhead while maintaining compatibility with existing browser-based flow
This commit is contained in:
@@ -17,6 +17,7 @@ from config import (
|
||||
BROWSER_HEADLESS,
|
||||
BROWSER_RANDOM_FINGERPRINT,
|
||||
AUTH_PROVIDER,
|
||||
S2A_API_MODE,
|
||||
get_random_name,
|
||||
get_random_birthday,
|
||||
get_random_fingerprint
|
||||
@@ -31,7 +32,8 @@ from cpa_service import (
|
||||
)
|
||||
from s2a_service import (
|
||||
s2a_generate_auth_url,
|
||||
s2a_create_account_from_oauth
|
||||
s2a_create_account_from_oauth,
|
||||
s2a_api_authorize,
|
||||
)
|
||||
from logger import log
|
||||
|
||||
@@ -2939,14 +2941,21 @@ def perform_s2a_authorization(page, email: str, password: str) -> bool:
|
||||
"""执行 S2A 授权流程 (密码登录)
|
||||
|
||||
Args:
|
||||
page: 浏览器实例
|
||||
page: 浏览器实例 (API 模式下可为 None)
|
||||
email: 邮箱地址
|
||||
password: 密码
|
||||
|
||||
Returns:
|
||||
bool: 授权是否成功
|
||||
"""
|
||||
log.info(f"开始 S2A 授权: {email}", icon="code")
|
||||
# 检查是否使用 API 模式
|
||||
if S2A_API_MODE:
|
||||
log.info(f"使用 S2A API 模式授权: {email}", icon="code")
|
||||
success, result = s2a_api_authorize(email, password)
|
||||
return success
|
||||
|
||||
# 以下是浏览器模式
|
||||
log.info(f"开始 S2A 浏览器授权: {email}", icon="code")
|
||||
progress_update(phase="授权", step="开始 S2A 授权...")
|
||||
|
||||
# 注意: 授权回调锁已在上层函数 (register_and_authorize/authorize_only) 中获取
|
||||
|
||||
Reference in New Issue
Block a user