Codex-LB uses OAuth 2.0 to authenticate ChatGPT accounts and automatically refreshes tokens to keep them valid. This page explains the OAuth flow, configuration options, and how to handle different deployment scenarios.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Soju06/codex-lb/llms.txt
Use this file to discover all available pages before exploring further.
OAuth Flow Overview
Codex-LB supports two OAuth authentication methods:- Browser Authorization Flow: User logs in via browser (default)
- Device Code Flow: User enters a code on a separate device
Authorization Code Flow
OAuth Configuration Variables
Base URL for the OpenAI authentication service.
OAuth client ID for OpenAI authentication.
OAuth scopes to request during authorization. Codex-LB automatically adds
offline_access to obtain refresh tokens.The full scope sent to OpenAI is: openid profile email offline_accessOAuth redirect URI for the authorization callback.Important considerations:
- Must match the registered redirect URI for the OAuth client
- Use
http://localhost:1455/auth/callbackfor local development - For remote deployments, see Remote Access Setup
Host address for the OAuth callback server to bind to.
- Local development:
127.0.0.1(default) - Docker:
0.0.0.0(automatically set in containers) - Remote server:
0.0.0.0(listen on all interfaces)
Port for the OAuth callback server.
Timeout in seconds for OAuth authorization and token exchange requests.
Token Refresh Configuration
Codex-LB automatically refreshes account tokens to prevent them from expiring.Timeout in seconds for token refresh requests.
Interval in days between automatic token refreshes.Codex-LB refreshes tokens every 8 days by default to keep them valid. OpenAI refresh tokens typically expire after 14-30 days of inactivity.
How Token Refresh Works
- Background Scheduler: Codex-LB runs a background task that checks all accounts
- Refresh Check: For each account, it checks if
current_time - last_refresh > REFRESH_INTERVAL_DAYS - Refresh Request: If refresh is needed, Codex-LB sends a refresh token request to OpenAI
- Token Update: New access token, refresh token, and ID token are encrypted and stored
- Error Handling: If refresh fails permanently (token expired/revoked), the account is marked for re-authentication
Permanent Refresh Errors
These errors require the user to re-authenticate:refresh_token_expired: Refresh token has expiredrefresh_token_reused: Refresh token was used more than oncerefresh_token_invalidated: User revoked access or changed password
Deployment Scenarios
Local Development
Default configuration works out of the box:http://localhost:2455 and add accounts normally.
Docker (Local)
For Docker running on localhost:http://localhost:2455.
Remote Server
For remote deployments, you have two options:Option 1: SSH Tunnel (Recommended)
Option 1: SSH Tunnel (Recommended)
Use SSH port forwarding to tunnel the callback port to your local machine:Then access the dashboard at
http://localhost:2455. OAuth callbacks will be tunneled through SSH.Advantages:- No firewall configuration needed
- No public exposure of callback port
- Works with default OAuth settings
Option 2: Public Access
Option 2: Public Access
Expose both the dashboard and callback ports publicly:Configure your firewall to allow:
- Port 2455 (dashboard)
- Port 1455 (OAuth callback)
- Use HTTPS with a reverse proxy (see below)
- Restrict dashboard access with password + TOTP
- Consider using firewall IP allowlists
Reverse Proxy (nginx/Caddy)
For production deployments, use a reverse proxy with HTTPS:PKCE (Proof Key for Code Exchange)
Codex-LB implements PKCE (RFC 7636) for additional security during OAuth authorization:- Code Verifier: Random 32-byte string generated for each auth request
- Code Challenge: SHA-256 hash of the verifier, sent with authorization request
- Verification: OpenAI verifies the verifier matches the challenge during token exchange
Device Code Flow
For headless servers or environments without browser access, Codex-LB supports the device code flow:- User clicks “Add Account” in dashboard
- Dashboard displays a verification URL and code
- User visits the URL on another device and enters the code
- User authenticates and authorizes access
- Codex-LB polls OpenAI until authorization is complete
Troubleshooting
OAuth Redirect Mismatch
OAUTH_REDIRECT_URI doesn’t match the registered URI.
Solution: Verify the redirect URI exactly matches (including protocol and port):
- Local:
http://localhost:1455/auth/callback - Remote:
http://your-server:1455/auth/callbackorhttps://your-domain:1455/auth/callback
Callback Timeout
- Port 1455 is blocked by firewall
- OAuth callback server isn’t listening
- User didn’t complete authorization in time
- Check firewall rules:
sudo ufw allow 1455/tcp - Verify Codex-LB is running and bound to correct host
- Increase
OAUTH_TIMEOUT_SECONDS
Token Refresh Failures
- Go to dashboard → Accounts
- Find the failed account
- Click “Re-login”
- Complete OAuth flow
Security Best Practices
Encrypt Tokens
Codex-LB encrypts all access and refresh tokens using a key file. Back up
encryption.key securely.Use HTTPS
Always use HTTPS in production to prevent token interception during OAuth callbacks.
Restrict Dashboard
Enable password + TOTP authentication for the dashboard in Settings.
Regular Refresh
Keep
TOKEN_REFRESH_INTERVAL_DAYS at 8 or lower to ensure tokens stay valid.