xtekky/gpt4free · error · RuntimeError
No authorization code received
Error message
No authorization code received
What it means
The callback server received a redirect request, but the query parameters contained no 'code'. In Google's OAuth redirect this happens when consent fails — the redirect then carries error=access_denied (or an admin policy blocks it) instead of an authorization code.
Source
Thrown at g4f/Provider/needs_auth/GeminiCLI.py:1223
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...")
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']}")
return tokens
finally:
callback_server.stop()
else:
print(
"\nAfter completing authentication, you'll be redirected to a localhost URL."View on GitHub (pinned to 973504e177)
Solutions
- Restart login and click Allow on the consent screen
- If access is blocked by an admin policy, use a personal or allowed account
- Check the callback URL's other params (error, error_description) to confirm denial
- Make sure only the login flow uses the callback port
Defensive patterns
Strategy: try-catch
Validate before calling
from urllib.parse import urlparse, parse_qs
def callback_has_code(redirect_url: str) -> bool:
q = parse_qs(urlparse(redirect_url).query)
return bool(q.get("code", [None])[0]) and "error" not in q Try / catch
try:
tokens = await GeminiCLI.login()
except RuntimeError as e:
if "No authorization code received" in str(e):
# consent denied or blocked: instruct user, do not auto-retry
raise AuthUserAction("approve the Google consent screen and retry") Prevention
- Check the callback's error param — access_denied is the usual sibling
- Do not probe the callback port from other tools during login
When it happens
Trigger: User clicks Cancel or Deny on the Google consent screen; Workspace admin policy auto-denies the app; the callback URL is hit by something else (health check, favicon request) with no code parameter.
Common situations: Accidental cancellation; the OAuth client flagged as unverified so users back out; automated environments probing the localhost port.
Related errors
- Missing PKCE verifier in state parameter
- Token exchange failed: {error_text}
- Missing tokens in response
- OAuth callback timed out
- No input provided
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/f783000859a03e1b.
Report an issue: GitHub.