xtekky/gpt4free · error · Exception
Authorization was denied by the user.
Error message
Authorization was denied by the user.
What it means
A bare Exception raised inside pollDeviceToken when the token endpoint returns the RFC 8628 error 'access_denied'. Unlike pending/expired states, this is a terminal, deliberate outcome: the user (or an org policy on their behalf) rejected the authorization request at the verification page, so no token will ever be issued for this device_code.
Source
Thrown at g4f/Provider/github/githubOAuth2.py:152
GITHUB_TOKEN_ENDPOINT,
headers={
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
},
data=object_to_urlencoded(body_data),
) as resp:
resp_json = await resp.json()
# Check for OAuth RFC 8628 responses
if "error" in resp_json:
if resp_json["error"] == "authorization_pending":
return {"status": "pending"}
if resp_json["error"] == "slow_down":
return {"status": "pending", "slowDown": True}
if resp_json["error"] == "expired_token":
raise Exception("Device code expired. Please try again.")
if resp_json["error"] == "access_denied":
raise Exception("Authorization was denied by the user.")
raise Exception(
f"Token poll failed: {resp_json.get('error')} - {resp_json.get('error_description')}"
)
return resp_json
def isTokenValid(self, credentials: GithubCredentials) -> bool:
"""GitHub tokens don't expire by default, but we track expiry_date if set"""
if not credentials.get("access_token"):
return False
expiry_date = credentials.get("expiry_date")
if expiry_date is None:
# GitHub tokens don't expire unless explicitly set
return True
return time.time() * 1000 < expiry_date - TOKEN_REFRESH_BUFFER_MS
View on GitHub (pinned to 973504e177)
Solutions
- Restart the flow and approve the requested scopes on the verification page
- If an org manages the account, request the g4f OAuth app be allowlisted or use a personal account
- Treat access_denied as non-retryable for this code — do not loop polling after catching it
Defensive patterns
Strategy: try-catch
Try / catch
try:
result = await client.pollDeviceToken({'device_code': code})
except Exception as e:
if 'denied' in str(e).lower():
abort_login() # terminal: user or org policy refused — do not retry this code
raise Prevention
- Treat access_denied as terminal for the current device_code; only a fresh flow can succeed
- For enterprise GitHub accounts, confirm the OAuth app is allowlisted before offering login
- Show a clear 'authorization denied' message instead of retrying silently
When it happens
Trigger: During device login the user clicked 'Deny'/cancel on github.com/login/device, or an organization's OAuth policy auto-denied the g4f application.
Common situations: User mistyped/abandoned the flow and denied it to dismiss the page; enterprise-managed GitHub accounts with restricted third-party OAuth app allowlists blocking g4f's client_id.
Related errors
- Device authorization failed {resp.status}: {resp_json}
- Device authorization error: {resp_json.get('error')} - {resp
- Device code expired. Please try again.
- device_code is required for polling
- Device authorization failed {resp.status}: {resp_json}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/07ae6081b6a855bd.
Report an issue: GitHub.