# run_browser_login

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/integrations/openai_codex/run_browser_login)

Run the ChatGPT OAuth Authorization Code Flow with PKCE.

Reimplements the upstream `langchain_openai.chatgpt_oauth` browser
sign-in flow over its lower-level helpers, but routes the authorize-URL
display through `interaction` so a Textual screen can render it inline.
The blocking callback wait and the synchronous token exchange both run
inside `asyncio.to_thread` so the calling event loop stays responsive.

## Signature

```python
run_browser_login(
    interaction: CodexLoginInteraction | None = None,
    *,
    store_path: Path | None = None,
    open_browser: bool = True,
    cancel_event: threading.Event | None = None,
) -> CodexAuthStatus
```

## Description

!!! note

`_wait_for_oauth_callback` raises `TimeoutError` after 300s of
inactivity; that exception propagates unchanged.

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `interaction` | `CodexLoginInteraction \| None` | No | UI hooks for surfacing the URL / notices. A default stdout-based implementation is used when `None`. (default: `None`) |
| `store_path` | `Path \| None` | No | Override the token store path. Defaults to `default_store_path()` (`~/.deepagents/.state/chatgpt-auth.json`). (default: `None`) |
| `open_browser` | `bool` | No | Whether to call `webbrowser.open`. Disable in headless environments or tests. (default: `True`) |
| `cancel_event` | `threading.Event \| None` | No | Optional event the caller can set to abandon the wait. Polled between callback server requests by `_wait_for_oauth_callback`, so setting it stops the wait and closes the loopback server within one poll interval (~1s), freeing the port for an immediate retry. (default: `None`) |

## Returns

`CodexAuthStatus`

A fresh `CodexAuthStatus` reflecting the just-saved token.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/e14e0adcbe78565ed3650e7f24b2a775d5437d25/libs/code/deepagents_code/integrations/openai_codex.py#L269)