feat: change OAuth login command for providers

This commit is contained in:
qiupinhua 2026-02-13 18:37:21 +08:00
parent c6915d27e9
commit 09c7e7aded
2 changed files with 23 additions and 14 deletions

View File

@ -597,6 +597,7 @@ That's it! Environment variables, model prefixing, config matching, and `nanobot
| `nanobot agent --logs` | Show runtime logs during chat | | `nanobot agent --logs` | Show runtime logs during chat |
| `nanobot gateway` | Start the gateway | | `nanobot gateway` | Start the gateway |
| `nanobot status` | Show status | | `nanobot status` | Show status |
| `nanobot provider login openai-codex` | OAuth login for providers |
| `nanobot channels login` | Link WhatsApp (scan QR) | | `nanobot channels login` | Link WhatsApp (scan QR) |
| `nanobot channels status` | Show channel status | | `nanobot channels status` | Show channel status |

View File

@ -860,9 +860,12 @@ def status():
# OAuth Login # OAuth Login
# ============================================================================ # ============================================================================
provider_app = typer.Typer(help="Manage providers")
app.add_typer(provider_app, name="provider")
@app.command()
def login( @provider_app.command("login")
def provider_login(
provider: str = typer.Argument(..., help="OAuth provider to authenticate with (e.g., 'openai-codex')"), provider: str = typer.Argument(..., help="OAuth provider to authenticate with (e.g., 'openai-codex')"),
): ):
"""Authenticate with an OAuth provider.""" """Authenticate with an OAuth provider."""
@ -870,19 +873,24 @@ def login(
if provider == "openai-codex": if provider == "openai-codex":
try: try:
from oauth_cli_kit import get_token as get_codex_token from oauth_cli_kit import get_token, login_oauth_interactive
token = None
console.print("[cyan]Starting OpenAI Codex authentication...[/cyan]") try:
console.print("A browser window will open for you to authenticate.\n") token = get_token()
except Exception:
token = get_codex_token() token = None
if not (token and token.access):
if token and token.access: console.print("[cyan]No valid token found. Starting interactive OAuth login...[/cyan]")
console.print(f"[green]✓ Successfully authenticated with OpenAI Codex![/green]") console.print("A browser window may open for you to authenticate.\n")
console.print(f"[dim]Account ID: {token.account_id}[/dim]") token = login_oauth_interactive(
else: 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]") console.print("[red]✗ Authentication failed[/red]")
raise typer.Exit(1) 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: except ImportError:
console.print("[red]oauth_cli_kit not installed. Run: pip install oauth-cli-kit[/red]") console.print("[red]oauth_cli_kit not installed. Run: pip install oauth-cli-kit[/red]")
raise typer.Exit(1) raise typer.Exit(1)