From 448df1a40bfd164672a18e8f3ea063e1960f6d85 Mon Sep 17 00:00:00 2001 From: Yukino_fox Date: Sat, 4 Apr 2026 15:13:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E6=94=B9=E8=BF=9B=20OAuth=20?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E6=B5=81=E7=A8=8B=E5=92=8C=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 JSON payload 改为 form 参数提交 - 使用 sessionStorage 存储 state 防止丢失 - 优化 OAuth 回调页面的 UI 和动画效果 - 修复状态检查逻辑并立即取消监听防止重复触发 --- src-tauri/src/commands/auth.rs | 22 ++- src-tauri/src/commands/oauth_server.rs | 186 ++++++++++++++++++++----- src/components/OAuth/OAuthLogin.tsx | 23 ++- 3 files changed, 176 insertions(+), 55 deletions(-) diff --git a/src-tauri/src/commands/auth.rs b/src-tauri/src/commands/auth.rs index 195870c..097a4b5 100644 --- a/src-tauri/src/commands/auth.rs +++ b/src-tauri/src/commands/auth.rs @@ -358,19 +358,19 @@ pub async fn oauth_exchange_code( println!("[OAuth] 换取令牌 - code: {}, platform_id: {}, callback_url: {}", code, platform_id, callback_url); let client = reqwest::Client::new(); - let payload = serde_json::json!({ - "grant_type": "authorization_code", - "code": code, - "client_id": platform_id, - "client_secret": platform_secret, - "redirect_uri": callback_url - }); + let params = [ + ("grant_type", "authorization_code"), + ("code", &code), + ("client_id", &platform_id), + ("client_secret", &platform_secret), + ("redirect_uri", &callback_url), + ]; - println!("[OAuth] 请求体:{:?}", payload); + println!("[OAuth] 请求参数:{:?}", params); let response = client .post("https://sectl.top/api/oauth/token") - .json(&payload) + .form(¶ms) .send() .await .map_err(|e| format!("Request failed: {}", e))?; @@ -379,10 +379,8 @@ pub async fn oauth_exchange_code( let response_text = response.text().await.map_err(|e| format!("Failed to read response: {}", e))?; println!("[OAuth] 响应内容:{}", response_text); - - let status_success = response_text.is_empty() || !response_text.contains("error"); - if !status_success { + if !response_text.is_empty() && response_text.contains("error") { return Ok(IpcResponse::error(&response_text)); } diff --git a/src-tauri/src/commands/oauth_server.rs b/src-tauri/src/commands/oauth_server.rs index 2596d31..a1e2a41 100644 --- a/src-tauri/src/commands/oauth_server.rs +++ b/src-tauri/src/commands/oauth_server.rs @@ -124,42 +124,99 @@ async fn handle_oauth_callback( OAuth 授权完成
-

✓ 授权成功

+
+ + + +
+

授权成功

请返回 SecScore 应用查看登录结果

-

此窗口可以关闭

+

此窗口可以关闭