{"record":{"id":"3209acaddb532956","repo":"xtekky/gpt4free","slug":"oauth-callback-timed-out-3209ac","errorCode":null,"errorMessage":"OAuth callback timed out","messagePattern":"OAuth callback timed out","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/GeminiCLI.py","lineNumber":1217,"sourceCode":"                print(\"Please open the URL above manually.\\n\")\n        else:\n            if not server_started:\n                print(\n                    f\"\\nCould not start local callback server on port {GEMINICLI_OAUTH_CALLBACK_PORT}.\"\n                )\n                print(\"You may need to close any application using that port.\\n\")\n\n            print(f\"\\nPlease open this URL in your browser:\\n\")\n            print(f\"{auth_url}\\n\")\n\n        if server_started:\n            print(\"Waiting for authentication callback...\")\n\n            try:\n                callback_result = callback_server.wait_for_callback()\n\n                if not callback_result:\n                    raise RuntimeError(\"OAuth callback timed out\")\n\n                code = callback_result.get(\"code\")\n                callback_state = callback_result.get(\"state\")\n\n                if not code:\n                    raise RuntimeError(\"No authorization code received\")\n\n                print(\"\\n✓ Authorization code received. Exchanging for tokens...\")\n\n                tokens = await cls.exchange_code_for_tokens(\n                    code, callback_state or state\n                )\n\n                print(f\"✓ Authentication successful!\")\n                if tokens.get(\"email\"):\n                    print(f\"  Logged in as: {tokens['email']}\")\n\n                return tokens","sourceCodeStart":1199,"sourceCodeEnd":1235,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/GeminiCLI.py#L1199-L1235","documentation":"The local OAuth callback server's wait_for_callback() returned a falsy result: no callback request arrived before the wait expired, so the browser never hit the localhost redirect. The login flow cannot obtain an authorization code without that redirect.","triggerScenarios":"User opens the auth URL but does not complete consent, or consent redirects elsewhere; the localhost callback server is blocked (port in use, firewall, remote container) so the redirect never reaches it.","commonSituations":"Running login inside a container or remote host where localhost is not the browser's localhost; another process holding the callback port; user closes the tab; slow consent flow exceeding the wait window.","solutions":["Ensure the machine running g4f is the same machine the browser runs on, or forward the callback port","Free the callback port (the flow prints which one) and retry","If port binding is impossible, use the manual paste mode instead of the callback server","Complete the Google consent screen promptly after opening the URL"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"import socket\n\ndef callback_port_free(port: int) -> bool:\n    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:\n        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n        try:\n            s.bind((\"127.0.0.1\", port))\n            return True\n        except OSError:\n            return False","typeGuard":null,"tryCatchPattern":"for attempt in range(2):\n    try:\n        tokens = await GeminiCLI.login()\n        break\n    except RuntimeError as e:\n        if \"OAuth callback timed out\" in str(e) and attempt == 0:\n            continue  # user was slow; try again with a fresh URL\n        raise","preventionTips":["Run login on the same host as the browser, or port-forward the callback","Free the callback port before starting; the flow prints it on conflict","Open the auth URL immediately and complete consent without long pauses"],"tags":["oauth","gemini","login","callback-server","localhost"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}