{"record":{"id":"317329959f0b72ec","repo":"slopus/happy","slug":"no-authorization-code-received","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/authenticateClaude.ts","lineNumber":155,"sourceCode":"): Promise<ClaudeAuthTokens> {\n    return new Promise((resolve, reject) => {\n        const server = createServer(async (req: IncomingMessage, res: ServerResponse) => {\n            const url = new URL(req.url!, `http://localhost:${port}`);\n\n            if (url.pathname === '/callback') {\n                const code = url.searchParams.get('code');\n                const receivedState = url.searchParams.get('state');\n\n                if (receivedState !== state) {\n                    res.writeHead(400);\n                    res.end('Invalid state parameter');\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, state);\n\n                    // Redirect to Anthropic's success page\n                    res.writeHead(302, {\n                        'Location': 'https://console.anthropic.com/oauth/code/success?app=claude-code'\n                    });\n                    res.end();\n\n                    server.close();\n                    resolve(tokens);","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/commands/connect/authenticateClaude.ts#L137-L173","documentation":"After state validation, the callback requires a 'code' query parameter containing the OAuth authorization code. If the redirect arrives without a code (e.g. the user denied consent or the provider returned an error response), the server responds 400 and rejects with 'No authorization code received'.","triggerScenarios":"Authorization redirect to /callback lacking the code parameter — user clicked 'deny'/'cancel' on the consent screen, provider returned error=access_denied instead of code, or the redirect URL was opened out of order.","commonSituations":"User aborts the browser consent flow; authorization session expired so the provider redirects without issuing a code; misconfigured redirect URI causing provider error responses.","solutions":["Restart the authentication flow and approve the permissions prompt in the browser","Check the callback URL for an error query parameter (e.g. error=access_denied) indicating why no code was issued","Ensure the redirect URI registered with the OAuth app matches exactly, including port and path","Complete the flow promptly — don't let the authorize URL sit until the provider session expires"],"exampleFix":"// before\nif (!code) {\n    res.writeHead(400);\n    res.end('No authorization code received');\n// after\nconst oauthError = url.searchParams.get('error');\nif (!code) {\n    res.writeHead(400);\n    res.end(oauthError ? `Authorization failed: ${oauthError}` : 'No authorization code received');","handlingStrategy":"validation","validationCode":"const callbackUrl = new URL(redirectedUrl);\nif (!callbackUrl.searchParams.get('code')) {\n  const err = callbackUrl.searchParams.get('error');\n  console.error(err ? `Authorization denied: ${err}` : 'No code in callback — approve the consent screen');\n}","typeGuard":"function hasAuthCode(url: URL): boolean {\n  const code = url.searchParams.get('code');\n  return typeof code === 'string' && code.length > 0;\n}","tryCatchPattern":"try {\n  const tokens = await authenticateClaude();\n} catch (e) {\n  if (e.message === 'No authorization code received') {\n    console.error('Authorization was not granted; retry the connect flow and approve the prompt');\n  } else throw e;\n}","preventionTips":["Don't cancel/deny the browser consent prompt","Check for ?error= in the callback URL to learn why the code was missing","Complete the flow promptly so the provider session doesn't expire","Ensure the registered redirect URI matches exactly"],"tags":["oauth","authentication","callback"],"backgroundTag":"missing-oauth-code","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}