slopus/happy · error
No authorization code received
Error message
No authorization code received
What it means
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'.
Source
Thrown at packages/happy-cli/src/commands/connect/authenticateClaude.ts:155
): Promise<ClaudeAuthTokens> {
return new Promise((resolve, reject) => {
const server = createServer(async (req: IncomingMessage, res: ServerResponse) => {
const url = new URL(req.url!, `http://localhost:${port}`);
if (url.pathname === '/callback') {
const code = url.searchParams.get('code');
const receivedState = url.searchParams.get('state');
if (receivedState !== state) {
res.writeHead(400);
res.end('Invalid state parameter');
server.close();
reject(new Error('Invalid state parameter'));
return;
}
if (!code) {
res.writeHead(400);
res.end('No authorization code received');
server.close();
reject(new Error('No authorization code received'));
return;
}
try {
// Exchange code for tokens
const tokens = await exchangeCodeForTokens(code, verifier, port, state);
// Redirect to Anthropic's success page
res.writeHead(302, {
'Location': 'https://console.anthropic.com/oauth/code/success?app=claude-code'
});
res.end();
server.close();
resolve(tokens);View on GitHub (pinned to b824cd0a46)
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
Example fix
// before
if (!code) {
res.writeHead(400);
res.end('No authorization code received');
// after
const oauthError = url.searchParams.get('error');
if (!code) {
res.writeHead(400);
res.end(oauthError ? `Authorization failed: ${oauthError}` : 'No authorization code received'); Defensive patterns
Strategy: validation
Validate before calling
const callbackUrl = new URL(redirectedUrl);
if (!callbackUrl.searchParams.get('code')) {
const err = callbackUrl.searchParams.get('error');
console.error(err ? `Authorization denied: ${err}` : 'No code in callback — approve the consent screen');
} Type guard
function hasAuthCode(url: URL): boolean {
const code = url.searchParams.get('code');
return typeof code === 'string' && code.length > 0;
} Try / catch
try {
const tokens = await authenticateClaude();
} catch (e) {
if (e.message === 'No authorization code received') {
console.error('Authorization was not granted; retry the connect flow and approve the prompt');
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: User aborts the browser consent flow; authorization session expired so the provider redirects without issuing a code; misconfigured redirect URI causing provider error responses.
Related errors
- No authorization code received
- No authorization code received
- Token exchange failed: ${tokenResponse.statusText}
- Token exchange failed: ${error}
- Token exchange failed: ${error}
AI-assisted analysis of slopus/happy@b824cd0a46 (2026-08-31).
Data as JSON: /api/errors/317329959f0b72ec.
Report an issue: GitHub.