feat: auto-fetch codex login otp from mailbox
This commit is contained in:
@@ -198,12 +198,14 @@ class CodexOAuthHTTPFlow:
|
||||
otp: str = "",
|
||||
workspace_id: str = "",
|
||||
use_browser: bool = False,
|
||||
mailbox: dict | None = None,
|
||||
) -> None:
|
||||
self.authorize_url = authorize_url
|
||||
self.email = email
|
||||
self.password = password
|
||||
self.otp = otp
|
||||
self.workspace_id = workspace_id
|
||||
self.mailbox = mailbox
|
||||
self.auth_base = "https://auth.openai.com"
|
||||
self.proxy = load_proxy()
|
||||
self.http = HTTPClient(self.proxy)
|
||||
@@ -304,13 +306,36 @@ class CodexOAuthHTTPFlow:
|
||||
print(f"[otp] sending email code via {send_url}")
|
||||
return self._api_json("GET", send_url, referer=referer)
|
||||
|
||||
def _fetch_otp_from_mailbox(self) -> str:
|
||||
"""Try to fetch OTP from mailbox automatically."""
|
||||
if not self.mailbox:
|
||||
return ""
|
||||
from vmail_client import MailClient
|
||||
mail = MailClient()
|
||||
print("[otp] auto-fetching OTP from mailbox...")
|
||||
try:
|
||||
code = mail.wait_for_otp(self.mailbox, timeout=120, poll=3.0)
|
||||
print(f" OTP: {code}")
|
||||
return code
|
||||
except Exception as e:
|
||||
print(f"[otp] auto-fetch failed: {e}")
|
||||
return ""
|
||||
|
||||
def _validate_email_otp(self, referer: str) -> dict[str, Any]:
|
||||
validate_url = f"{self.auth_base}/api/accounts/email-otp/validate"
|
||||
resend_url = f"{self.auth_base}/api/accounts/email-otp/resend"
|
||||
|
||||
while True:
|
||||
code = (self.otp or input("Email OTP (or type 'resend'): ").strip()).strip()
|
||||
self.otp = ""
|
||||
if self.otp:
|
||||
code = self.otp.strip()
|
||||
self.otp = ""
|
||||
elif self.mailbox:
|
||||
code = self._fetch_otp_from_mailbox()
|
||||
if not code:
|
||||
raise FlowError("Failed to auto-fetch OTP from mailbox")
|
||||
else:
|
||||
code = input("Email OTP (or type 'resend'): ").strip()
|
||||
|
||||
if not code:
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user