{"record":{"id":"fe3325c0204bcb4e","repo":"jlcodes99/cockpit-tools","slug":"oauth-fe3325","errorCode":null,"errorMessage":"OAuth 流程失败: {}","messagePattern":"OAuth 流程失败: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/commands/oauth.rs","lineNumber":55,"sourceCode":"    }\n}\n\n#[tauri::command]\npub async fn start_oauth_login(\n    app_handle: AppHandle,\n    note: Option<String>,\n    two_factor_secret: Option<String>,\n    account_password: Option<String>,\n    phone_number: Option<String>,\n    mail_url: Option<String>,\n    aux_email: Option<String>,\n) -> Result<models::Account, String> {\n    modules::logger::log_info(\"开始 OAuth 授权流程...\");\n\n    let token_res = modules::oauth_server::start_oauth_flow(app_handle.clone())\n        .await\n        .map_err(|e| {\n            modules::logger::log_error(&format!(\"OAuth 流程失败: {}\", e));\n            e\n        })?;\n\n    modules::logger::log_info(\"OAuth 授权成功，检查 refresh_token...\");\n\n    let refresh_token = token_res.refresh_token.ok_or_else(|| {\n        let msg = \"未获取到 Refresh Token。\\n\\n\\\n         可能原因：您之前已授权过此应用\\n\\n\\\n         解决方案：\\n\\\n         1. 访问 https://myaccount.google.com/permissions\\n\\\n         2. 撤销 'Antigravity Tools' 的访问权限\\n\\\n         3. 重新进行 OAuth 授权\"\n            .to_string();\n        modules::logger::log_error(&msg);\n        msg\n    })?;\n\n    modules::logger::log_info(\"获取用户信息...\");","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src-tauri/src/commands/oauth.rs#L37-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nlet token_res = modules::oauth_server::start_oauth_flow(app_handle.clone())\n    .await\n    .map_err(|e| {\n        modules::logger::log_error(&format!(\"OAuth 流程失败: {}\", e));\n        e\n    })?;\n// after\nlet token_res = modules::oauth_server::start_oauth_flow(app_handle.clone())\n    .await\n    .map_err(|e| {\n        modules::logger::log_error(&format!(\"OAuth 流程失败: {}\", e));\n        format!(\"OAuth 授权流程失败，请重试并完成浏览器授权: {}\", e)\n    })?;","handlingStrategy":"try-catch","validationCode":"// pre-flight checks before launching the OAuth flow\nif !callback_port_available().await {\n    return Err(\"本地回调端口被占用，请关闭其他实例后重试\".to_string());\n}\nif !oauth_client_configured() {\n    return Err(\"缺少 Google OAuth client_id/client_secret 配置\".to_string());\n}\nif !reachable(\"https://accounts.google.com\").await {\n    return Err(\"无法访问 Google 授权服务，请检查网络/代理\".to_string());\n}","typeGuard":null,"tryCatchPattern":"let token_res = match modules::oauth_server::start_oauth_flow(app_handle.clone()).await {\n    Ok(t) => t,\n    Err(e) => {\n        log_error(&format!(\"OAuth 流程失败: {}\", e));\n        return Err(format!(\"OAuth 授权流程失败，请重试并在浏览器中完成授权: {}\", e));\n    }\n};","preventionTips":["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"],"tags":["oauth","google","callback-server","token-exchange"],"backgroundTag":"oauth-flow-failed","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}