Skip to content

Your lightweight open-source personal agent.

feat: change OAuth login command for providers

qiupinhua09c7e7adedb0
diff --git a/README.md b/README.md
index eb2ff7f3d..8d0ab4db2 100644
--- a/README.md
+++ b/README.md
@@ -597,6 +597,7 @@ That's it! Environment variables, model prefixing, config matching, and `nanobot
| `nanobot agent --logs` | Show runtime logs during chat |
| `nanobot gateway` | Start the gateway |
| `nanobot status` | Show status |
+| `nanobot provider login openai-codex` | OAuth login for providers |
| `nanobot channels login` | Link WhatsApp (scan QR) |
| `nanobot channels status` | Show channel status |
diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.py
index 1ee233257..f2a7ee381 100644
--- a/nanobot/cli/commands.py
+++ b/nanobot/cli/commands.py
@@ -860,29 +860,37 @@ def status():
# OAuth Login
# ============================================================================
+provider_app = typer.Typer(help="Manage providers")
+app.add_typer(provider_app, name="provider")
-def login(
+
+@provider_app.command("login")
+def provider_login(
provider: str = typer.Argument(..., help="OAuth provider to authenticate with (e.g., 'openai-codex')"),
):
"""Authenticate with an OAuth provider."""
console.print(f"{__logo__} OAuth Login - {provider}\n")
-
+
if provider == "openai-codex":
try:
- from oauth_cli_kit import get_token as get_codex_token
-
- console.print("[cyan]Starting OpenAI Codex authentication...[/cyan]")
- console.print("A browser window will open for you to authenticate.\n")
-
- token = get_codex_token()
-
- if token and token.access:
- console.print(f"[green]✓ Successfully authenticated with OpenAI Codex![/green]")
- console.print(f"[dim]Account ID: {token.account_id}[/dim]")
- else:
+ from oauth_cli_kit import get_token, login_oauth_interactive
+ token = None
+ try:
+ token = get_token()
+ except Exception:
+ token = None
+ if not (token and token.access):
+ console.print("[cyan]No valid token found. Starting interactive OAuth login...[/cyan]")
+ console.print("A browser window may open for you to authenticate.\n")
+ token = login_oauth_interactive(
+ print_fn=lambda s: console.print(s),
+ prompt_fn=lambda s: typer.prompt(s),
+ )
+ if not (token and token.access):
console.print("[red]✗ Authentication failed[/red]")
raise typer.Exit(1)
+ console.print("[green]✓ Successfully authenticated with OpenAI Codex![/green]")
+ console.print(f"[dim]Account ID: {token.account_id}[/dim]")
except ImportError:
console.print("[red]oauth_cli_kit not installed. Run: pip install oauth-cli-kit[/red]")
raise typer.Exit(1)