codex-oauth
PKCE OAuth login for OpenAI Codex — obtains an access token via a browser-based login against auth.openai.com, usable as a Bearer token with the ChatGPT backend API.
- crates.io: https://crates.io/crates/codex-oauth
- GitHub: https://github.com/motosan-dev/motosan-ai
Install
[]
= "0.1"
= { = "1", = ["rt-multi-thread", "macros"] }
Usage
Login
async
login() opens the browser to auth.openai.com (and prints the URL for manual opening) then listens on http://localhost:1455/auth/callback for the redirect. Times out after 120 seconds.
Refresh
let new_token = refresh.await?;
Expiry check
if token.is_expired
Persist to disk
Token implements serde::Serialize / Deserialize:
let json = to_string?;
// later:
let token: Token = from_str?;
Use with OpenAI provider (motosan-ai)
let token = login.await?;
let client = builder
.provider
.api_key
.base_url
.build?;
Notes
- Port
1455must be free — it is hardcoded by OpenAI's app registration. CLIENT_IDis OpenAI's public Codex app registration (app_EMoamEEZ73f0CkXaXp7hrann) and is not configurable.- Requires a ChatGPT account.