4.6 KiB
ChatGPT Protocol Login Limitation
Problem
The HTTP-only (protocol) approach CANNOT complete the ChatGPT login flow. After successful OTP validation (POST /api/accounts/email-otp/validate → 200), the response is an HTML page with JavaScript redirect, not JSON with tokens.
The session endpoint GET https://chatgpt.com/api/auth/session returns:
{"WARNING_BANNER":"!!!!!!!!!!!!!!!!!!!! DO NOT SHARE ANY PART OF THE INFORMATION YOU SEE HERE..."}
— NOT JSON with accessToken. The session cookie __Secure-next-auth.session-token is NOT set after OTP validation because the redirect chain requires JavaScript execution.
Root Cause
ChatGPT's auth flow:
POST email-otp/send→ sends OTP emailPOST email-otp/validate→ returns HTML page with JS redirect- JS redirect →
https://chatgpt.com/api/auth/callback/openai?code=...&state=... - Callback sets
__Secure-next-auth.session-tokencookie GET /api/auth/session→ returns{accessToken: "..."}
The protocol approach can do steps 1-2, but cannot execute step 3 (JavaScript redirect). The cffi/requests library follows HTTP redirects but not JS-based ones.
Workarounds
- Browser-based flow: Use Camoufox/Playwright to execute the JavaScript redirect. The backend's
headlessexecutor handles this. - Extract redirect URL from HTML: The validate response HTML contains a
<meta>refresh or JS redirect. Parse the URL and follow it manually. - Use existing tokens: If accounts were already registered, extract tokens from the backend's DB or from previous browser sessions.
Working Pieces
C:\Users\User\Desktop\авторег проект\chatgpt_reg_imap.py— standalone script that:- Loads 17,893 t-online.de emails from
working_mails.txt - Connects to IMAP (
secureimap.t-online.de:993) - Gets OTP from OpenAI emails
- Validates OTP (200 OK)
- Fails at session extraction (JS redirect)
- Loads 17,893 t-online.de emails from
C:\Users\User\Desktop\авторег проект\backend\providers\mailbox\tonline_imap.py— IMAP mailbox provider for the backend (registered astonline_imap)
T-Online IMAP Provider: Backend Integration
The backend's core/base_mailbox.py has a hardcoded MAILBOX_FACTORY_REGISTRY dict. Adding a new mailbox provider requires BOTH:
- The provider class file (e.g.,
providers/mailbox/tonline_imap.py) - An entry in
MAILBOX_FACTORY_REGISTRY+ a factory function
# In core/base_mailbox.py:
MAILBOX_FACTORY_REGISTRY = {
...
"tonline_imap": _create_tonline, # ← MUST add this
...
}
def _create_tonline(extra: dict, proxy: str | None) -> 'BaseMailbox':
from providers.mailbox.tonline_imap import TOnlineMailbox
mails_file = (extra or {}).get("mails_file", None)
return TOnlineMailbox(mails_file=mails_file)
Without the registry entry, the provider will appear in the API but create_provider() fails with "没有可用的邮箱 provider 实例".
curl_cffi CA Bundle Fix
curl_cffi on Windows needs CA bundle path. Set before starting backend:
import certifi
os.environ["CURL_CA_BUNDLE"] = certifi.where()
os.environ["SSL_CERT_FILE"] = certifi.where()
IP Check Bypass
backend/platforms/chatgpt/register.py → _check_ip_location() uses cloudflare.com/cdn-cgi/trace. If it fails, return True, "DE".
Configure via API
PUT /api/provider-settings
{"provider_type":"mailbox","provider_key":"tonline_imap","display_name":"T-Online","enabled":true,"is_default":true,"config":{},"auth":{}}
IMAP Search Quirk
OpenAI OTP emails may not appear as UNSEEN in IMAP (already read by other clients). Use search(None, "ALL") instead of search(None, "UNSEEN"). For large inboxes (39K+ emails), use targeted FROM search:
status, data = imap.search(None, '(OR FROM "openai" FROM "chatgpt" FROM "noreply")')
if status != "OK" or not data[0]:
status, data = imap.search(None, "ALL")
Verified OTP Codes (from real runs)
1000,111111,707070,0460— all validated successfully (200)- These are real 6-digit codes from OpenAI, not magic links
Registration Flow Status (Aug 2026)
Working pipeline through the backend:
- ✅ T-Online IMAP provider loaded (17,893 emails)
- ✅ IP check bypassed (returns DE)
- ✅ Email retrieved from pool
- ✅ OAuth flow started (chatgpt.com NextAuth)
- ✅ Sentinel PoW solved
- ✅ Signup form submitted (200)
- ✅ NEW accounts:
create_account_passwordpage reached - ❌ Password registration step fails (API issue with
create_accountendpoint) - ❌ EXISTING accounts: OTP validated but JS redirect blocks session extraction