LemonAi. Auth. OpenAICodexOAuth
(lemon_ai v0.1.0)
View Source
OpenAI Codex OAuth helpers.
Supports PKCE authorization URL generation, manual code parsing, code/token exchange, refresh, and encrypted secret resolution.
Summary
Functions
Build an OAuth authorization URL + PKCE verifier/state.
Build an OAuth authorization URL + PKCE verifier/state.
Decode OAuth secret payload.
Encode OAuth secret payload for storage by the caller.
Exchange authorization code + PKCE verifier for an OAuth secret payload.
Run OpenAI Codex OAuth flow.
Parse manual pasted OAuth input. Accepts
Resolve a Codex access token from process environment values.
Resolve a usable Codex access token from an OAuth secret.
Types
@type login_opt() :: {:on_auth, (String.t(), String.t() | nil -> any())} | {:on_progress, (String.t() -> any())} | {:on_prompt, (map() -> String.t() | charlist())} | {:originator, String.t()} | {:redirect_uri, String.t()} | {:state, String.t()} | {:callback_timeout_ms, pos_integer()} | {:listen_for_callback, boolean()} | {:local_callback_listener, module()} | {:persist_secret, (String.t(), String.t() -> any())}
Functions
Build an OAuth authorization URL + PKCE verifier/state.
Build an OAuth authorization URL + PKCE verifier/state.
@spec decode_secret(String.t()) :: {:ok, oauth_secret()} | :not_oauth
Decode OAuth secret payload.
@spec encode_secret(oauth_secret()) :: String.t()
Encode OAuth secret payload for storage by the caller.
@spec exchange_code_for_secret(String.t(), String.t(), keyword()) :: {:ok, oauth_secret()} | {:error, term()}
Exchange authorization code + PKCE verifier for an OAuth secret payload.
@spec login_device_flow([login_opt()]) :: {:ok, oauth_secret()} | {:error, term()}
Run OpenAI Codex OAuth flow.
When the redirect URI is local (http://localhost:1455/auth/callback by default),
A local listener can capture the browser callback automatically and fall back to manual
paste only if that listener cannot complete the flow.
@spec parse_authorization_input(String.t()) :: {:ok, %{code: String.t(), state: String.t() | nil}} | {:error, term()}
Parse manual pasted OAuth input. Accepts:
- full callback URL
- query string containing
code= code#state- plain code
@spec resolve_access_token() :: String.t() | nil
Resolve a Codex access token from process environment values.
Resolution order:
OPENAI_CODEX_API_KEYCHATGPT_TOKEN
Resolve a usable Codex access token from an OAuth secret.
Returns :ignore for non-Codex-OAuth payloads.