{"record":{"id":"9a5a1d656724ab22","repo":"zeroclaw-labs/zeroclaw","slug":"could-not-parse-oauth-code-from-input","errorCode":null,"errorMessage":"Could not parse OAuth code from input","messagePattern":"Could not parse OAuth code from input","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-providers/src/auth/gemini_oauth.rs","lineNumber":521,"sourceCode":"\n    // If we have code param, extract it\n    if let Some(code) = params.get(\"code\") {\n        // Validate state if expected\n        if let Some(expected) = expected_state\n            && let Some(actual) = params.get(\"state\")\n            && actual != expected\n        {\n            anyhow::bail!(\"OAuth state mismatch: expected {expected}, got {actual}\");\n        }\n        return Ok(code.clone());\n    }\n\n    // Otherwise, assume it's the raw code (if long enough and no spaces)\n    if trimmed.len() > 10 && !trimmed.contains(' ') && !trimmed.contains('&') {\n        return Ok(trimmed.to_string());\n    }\n\n    anyhow::bail!(\"Could not parse OAuth code from input\")\n}\n\n/// Extract account email from Google ID token.\npub fn extract_account_email_from_id_token(id_token: &str) -> Option<String> {\n    let parts: Vec<&str> = id_token.split('.').collect();\n    if parts.len() != 3 {\n        return None;\n    }\n\n    let payload = base64::engine::general_purpose::URL_SAFE_NO_PAD\n        .decode(parts[1])\n        .ok()?;\n\n    #[derive(Deserialize)]\n    struct IdTokenPayload {\n        email: Option<String>,\n    }\n","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-providers/src/auth/gemini_oauth.rs#L503-L539","documentation":"parse_code_from_redirect could not interpret its input at all: there is no code query parameter, and the input fails the raw-code heuristic (length > 10, no spaces, no '&'). This is the terminal failure after both parsing strategies are exhausted, meaning the user pasted something that is neither a callback URL nor a plausible authorization code.","triggerScenarios":"Pasting a consent-error URL such as http://localhost:1456/auth/callback?error=access_denied (has no code param), a natural-language sentence (contains spaces), or a short fragment under 11 characters; also pasting a URL whose query string was mangled so code= is lost.","commonSituations":"Google redirected with an error instead of a code (access denied, app unverified) and the user pastes that URL; clipboard contains the wrong text; user pastes the verification user_code from the device flow instead of the authorization code.","solutions":["Go back to the authorize URL, complete consent, and paste the final callback URL that contains code=...","If the URL contains error=access_denied instead of code, the consent was denied — restart the login and click Allow","Paste just the raw authorization code (a long single token like 4/0AcvDM...) with no spaces or extra text"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let t = input.trim();\nlet looks_like_url_with_code = t.contains(\"code=\");\nlet looks_like_raw_code = t.len() > 10 && !t.contains(' ') && !t.contains('&');\nanyhow::ensure!(\n    looks_like_url_with_code || looks_like_raw_code,\n    \"input is neither a callback URL with code= nor a raw code; re-copy from the browser\"\n);","typeGuard":null,"tryCatchPattern":"match parse_code_from_redirect(input, expected_state) {\n    Ok(code) => code,\n    Err(e) if e.to_string() == \"Could not parse OAuth code from input\" => {\n        eprintln!(\"paste the full callback URL (it must contain code=...) or just the long code value\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Copy the final browser URL after consent, not the consent page URL","A raw code must be one long token: no spaces, no '&', longer than 10 characters","If the URL shows error=..., fix the consent problem instead of re-pasting"],"tags":["oauth","user-input","authorization-code","parse","rust"],"backgroundTag":"oauth-code-parse-failed","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}