{"record":{"id":"257f5ed77305a9d1","repo":"slopus/happy","slug":"no-authorization-code-received-257f5e","errorCode":null,"errorMessage":"No authorization code received","messagePattern":"No authorization code received","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"packages/happy-cli/src/commands/connect/authenticateGemini.ts","lineNumber":152,"sourceCode":"                    res.writeHead(302, { \n                        'Location': 'https://developers.google.com/gemini-code-assist/auth_failure_gemini' \n                    });\n                    res.end();\n                    server.close();\n                    reject(new Error(`Authentication error: ${error}`));\n                    return;\n                }\n                \n                if (receivedState !== state) {\n                    res.writeHead(400);\n                    res.end('State mismatch. Possible CSRF attack');\n                    server.close();\n                    reject(new Error('Invalid state parameter'));\n                    return;\n                }\n                \n                if (!code) {\n                    res.writeHead(400);\n                    res.end('No authorization code received');\n                    server.close();\n                    reject(new Error('No authorization code received'));\n                    return;\n                }\n                \n                try {\n                    // Exchange code for tokens\n                    const tokens = await exchangeCodeForTokens(code, verifier, port);\n                    \n                    // Redirect to success page\n                    res.writeHead(302, { \n                        'Location': 'https://developers.google.com/gemini-code-assist/auth_success_gemini' \n                    });\n                    res.end();\n                    \n                    server.close();\n                    resolve(tokens);","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/commands/connect/authenticateGemini.ts#L134-L170","documentation":"After the state check, the Gemini callback server requires a `code` query parameter on the /oauth2callback redirect; this code is exchanged at https://oauth2.googleapis.com/token for access/refresh tokens. If the redirect carries no `code` (Google instead appends an `error` parameter, which is checked earlier, or the parameter is missing entirely), the server responds 400 and rejects with 'No authorization code received'.","triggerScenarios":"Google redirects to /oauth2callback with matching state but without `code` — the consent screen was dismissed in a way that bypasses the `error` branch, the authorization request was rejected (unregistered redirect_uri, missing scope approval), or the callback URL was manually edited/stripped.","commonSituations":"User aborts the Google consent dialog; the Google Cloud OAuth client's authorized redirect URI doesn't include http://localhost:<port>/oauth2callback; `prompt=consent` flow interrupted; single-use code consumed by an earlier request so Google re-redirects without one.","solutions":["Inspect the callback URL in the browser for `error=` or `error_subtype=` parameters (e.g. access_denied) to learn why Google withheld the code.","Rerun `happy` connect and complete the Google consent screen fully, granting the requested cloud-platform/email/profile scopes.","Retry from scratch — authorization codes are single-use and short-lived; don't reload a callback URL.","Verify nothing (proxy, extension, manual editing) strips the `code` query parameter from the localhost redirect."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const tokens = await authenticateGemini();\n} catch (err) {\n  if (err instanceof Error && err.message === 'No authorization code received') {\n    // consent denied or provider withheld the code — surface guidance and retry\n    console.error('Google did not return an authorization code (likely denied consent or redirect_uri mismatch). Retry connect and approve all scopes.');\n  } else throw err;\n}","preventionTips":["Approve the full Google consent screen (cloud-platform, email, profile scopes); do not cancel midway.","Never reload or hand-edit a callback URL — codes are single-use and must arrive intact.","If failures repeat, check the callback URL for `error=`/`error_subtype=` params to diagnose (e.g. redirect_uri_mismatch).","Retry promptly: Google authorization codes expire within minutes."],"tags":["oauth","authorization-code","google","callback","authentication"],"backgroundTag":"missing-oauth-authorization-code","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}