feat(auth): 改进 OAuth 授权流程和界面

- 将 JSON payload 改为 form 参数提交
- 使用 sessionStorage 存储 state 防止丢失
- 优化 OAuth 回调页面的 UI 和动画效果
- 修复状态检查逻辑并立即取消监听防止重复触发
This commit is contained in:
Yukino_fox
2026-04-04 15:13:15 +08:00
parent c2fe7af7d0
commit 448df1a40b
3 changed files with 176 additions and 55 deletions
+10 -12
View File
@@ -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(&params)
.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));
}