jlcodes99/cockpit-tools · error
OAuth 流程失败: {}
Error message
OAuth 流程失败: {} What it means
start_oauth_login launches the full Google OAuth flow via modules::oauth_server::start_oauth_flow, which starts a local redirect server and waits for the authorization code/token exchange. This error is logged and returned when that flow fails for any reason, aborting the account-add operation before user info is fetched.
Source
Thrown at src-tauri/src/commands/oauth.rs:55
}
}
#[tauri::command]
pub async fn start_oauth_login(
app_handle: AppHandle,
note: Option<String>,
two_factor_secret: Option<String>,
account_password: Option<String>,
phone_number: Option<String>,
mail_url: Option<String>,
aux_email: Option<String>,
) -> Result<models::Account, String> {
modules::logger::log_info("开始 OAuth 授权流程...");
let token_res = modules::oauth_server::start_oauth_flow(app_handle.clone())
.await
.map_err(|e| {
modules::logger::log_error(&format!("OAuth 流程失败: {}", e));
e
})?;
modules::logger::log_info("OAuth 授权成功,检查 refresh_token...");
let refresh_token = token_res.refresh_token.ok_or_else(|| {
let msg = "未获取到 Refresh Token。\n\n\
可能原因:您之前已授权过此应用\n\n\
解决方案:\n\
1. 访问 https://myaccount.google.com/permissions\n\
2. 撤销 'Antigravity Tools' 的访问权限\n\
3. 重新进行 OAuth 授权"
.to_string();
modules::logger::log_error(&msg);
msg
})?;
modules::logger::log_info("获取用户信息...");View on GitHub (pinned to 1ed8b77992)
Solutions
- Retry the OAuth login and complete the browser authorization promptly in one sitting
- Check that the local callback port is free and not blocked by firewall/security software
- Verify the Google OAuth client_id/client_secret configuration and that the redirect URI matches the registered one
- Confirm network access to accounts.google.com (disable conflicting proxies/VPN if needed)
Example fix
// before
let token_res = modules::oauth_server::start_oauth_flow(app_handle.clone())
.await
.map_err(|e| {
modules::logger::log_error(&format!("OAuth 流程失败: {}", e));
e
})?;
// after
let token_res = modules::oauth_server::start_oauth_flow(app_handle.clone())
.await
.map_err(|e| {
modules::logger::log_error(&format!("OAuth 流程失败: {}", e));
format!("OAuth 授权流程失败,请重试并完成浏览器授权: {}", e)
})?; Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight checks before launching the OAuth flow
if !callback_port_available().await {
return Err("本地回调端口被占用,请关闭其他实例后重试".to_string());
}
if !oauth_client_configured() {
return Err("缺少 Google OAuth client_id/client_secret 配置".to_string());
}
if !reachable("https://accounts.google.com").await {
return Err("无法访问 Google 授权服务,请检查网络/代理".to_string());
} Try / catch
let token_res = match modules::oauth_server::start_oauth_flow(app_handle.clone()).await {
Ok(t) => t,
Err(e) => {
log_error(&format!("OAuth 流程失败: {}", e));
return Err(format!("OAuth 授权流程失败,请重试并在浏览器中完成授权: {}", e));
}
}; Prevention
- Complete the browser authorization promptly; don't let the flow time out
- Keep only one app instance running during OAuth (callback port conflicts)
- Verify redirect URI matches what's registered in the Google OAuth client
- Check proxy/VPN/firewall blocks against accounts.google.com
When it happens
Trigger: start_oauth_flow(app_handle) returns Err: the local callback server failed to bind, the user cancelled/did not complete browser authorization, the state/redirect handshake timed out, or the token exchange with Google returned an error.
Common situations: User closes the browser before authorizing; another app instance already holds the local callback port; Google OAuth client credentials (client_id/secret) missing or wrong in configuration; corporate proxy blocking accounts.google.com; authorization timeout because the user walked away.
Related errors
- OAuth 回调服务器错误: {}
- Token 交换失败: status={}, body_len={}
- 本地回调服务异常: {}
- [Windsurf OAuth] 回调服务恢复失败: login_id={}, error={}
- [Windsurf OAuth] 回调服务异常: login_id={}, error={}
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/fe3325c0204bcb4e.
Report an issue: GitHub.