xtekky/gpt4free · error · RuntimeError
No authorization code received
Error message
No authorization code received
What it means
The OAuth callback DID arrive, but its query string contained no 'code' parameter. Google redirects back with code only on successful consent; on failure it appends error=access_denied instead, so this usually means the user cancelled the consent screen or Google rejected the request before issuing a code.
Solutions
- Re-run login and click 'Allow' on the Google consent screen.
- If consent cannot be granted, the Google account/org is blocking the app — use an eligible account (see error 106).
- Check the callback URL logged by the local server for an error= parameter and address that specific OAuth error.
Defensive patterns
Strategy: try-catch
Validate before calling
def callback_has_code(callback_result: dict) -> bool:
return bool(callback_result and callback_result.get("code")) Type guard
def is_successful_callback(cb: object) -> bool:
"""True when the OAuth callback dict carries an authorization code."""
return isinstance(cb, dict) and isinstance(cb.get("code"), str) and len(cb["code"]) > 0 Try / catch
try:
tokens = await Antigravity.login()
except RuntimeError as e:
if "No authorization code received" in str(e):
# inspect callback URL for error=access_denied; guide user to click Allow
raise Prevention
- Instruct users to click 'Allow' on the Google consent screen
- Log the raw callback query string to distinguish denied consent from stripped parameters
- Avoid proxies/extensions that drop query parameters on localhost redirects
When it happens
Trigger: Callback URL like http://localhost:PORT/callback?state=... without code — e.g. ?error=access_denied. Also occurs when a proxy or browser security tool strips query parameters from the redirect.
Common situations: User clicked 'Cancel'/'Deny' on the Google consent page; Workspace policy auto-denies unapproved third-party OAuth apps; query params mangled by a redirecting SSO front-end.
Related errors
- OAuth callback timed out
- OAuth error
- Could not extract authorization code
- Failed to read OAuth credentials from
- Missing PKCE verifier in state parameter
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/ded9787811335b88.
Report an issue: GitHub.
Appendix: source
Thrown at g4f/Provider/needs_auth/Antigravity.py:862
print("You may need to close any application using that port.\n")
print(f"\nPlease open this URL in your browser:\n")
print(f"{auth_url}\n")
if server_started:
print("Waiting for authentication callback...")
try:
callback_result = callback_server.wait_for_callback()
if not callback_result:
raise RuntimeError("OAuth callback timed out")
code = callback_result.get("code")
callback_state = callback_result.get("state")
if not code:
raise RuntimeError("No authorization code received")
print("\n✓ Authorization code received. Exchanging for tokens...")
# Exchange code for tokens
tokens = await cls.exchange_code_for_tokens(
code, callback_state or state
)
print(f"✓ Authentication successful!")
if tokens.get("email"):
print(f" Logged in as: {tokens['email']}")
if tokens.get("project_id"):
print(f" Project ID: {tokens['project_id']}")
return tokens
finally:
callback_server.stop()View on GitHub (pinned to 973504e177)