# ConsoleAI agent login for Windows PowerShell (RFC 8628 device code). The token is never printed. # iwr https://cws-b681dbf7d6.hq-staging.abuz8ai.com/connect/login.ps1 -OutFile login.ps1; powershell -ExecutionPolicy Bypass -File .\login.ps1 -Name OpenClaw # .\login.ps1 -Name Hermes -Config "$env:USERPROFILE\.cursor\mcp.json" (also merge into a JSON MCP config: mcpServers.consoleai) # Writes: %USERPROFILE%\.consoleai\.token and .mcp.json param([Parameter(Mandatory=$true)][string]$Name, [string]$Config = "", [string]$Base = "https://cws-b681dbf7d6.hq-staging.abuz8ai.com") $ErrorActionPreference = "Stop" function Post($path, $body) { try { return Invoke-RestMethod -Method Post -Uri ($Base + $path) -Body $body -ContentType "application/x-www-form-urlencoded" } catch { $r = $_.ErrorDetails.Message; if ($r) { return ($r | ConvertFrom-Json) } throw } } $d = Post "/device_authorization" @{ client_name = $Name } if (-not $d.device_code) { Write-Error ("ConsoleAI refused: " + $d.error_description); exit 1 } Write-Host "" Write-Host " ConsoleAI login for: $Name" Write-Host " 1. On your phone or computer open: $($d.verification_uri_complete)" Write-Host " (or open $($d.verification_uri) and type the code)" Write-Host " 2. Sign in with your owner Google account." Write-Host " 3. Check the code matches, then tap Approve: $($d.user_code)" Write-Host "" Write-Host " Waiting (code expires in $([int]($d.expires_in/60)) minutes)..." $clientId = "cai-device-" + (($Name.ToLower() -replace '[^a-z0-9]+','-').Trim('-')) if ($clientId.Length -gt 51) { $clientId = $clientId.Substring(0,51) } if ($d.client_id) { $clientId = $d.client_id } $iv = [int]$d.interval; if ($iv -lt 1) { $iv = 5 } $end = (Get-Date).AddSeconds([int]$d.expires_in); $t = $null while ((Get-Date) -lt $end) { Start-Sleep -Seconds $iv $t = Post "/token" @{ grant_type = "urn:ietf:params:oauth:grant-type:device_code"; device_code = $d.device_code; client_id = $clientId } if ($t.access_token) { break } if ($t.error -eq "authorization_pending") { continue } if ($t.error -eq "slow_down") { $iv += 5; continue } Write-Error ("Login stopped: " + $t.error + " - " + $t.error_description); exit 1 } if (-not $t.access_token) { Write-Error "Login timed out. Run it again."; exit 1 } $dir = Join-Path $env:USERPROFILE ".consoleai"; New-Item -ItemType Directory -Force -Path $dir | Out-Null $entry = [ordered]@{ type = "http"; url = "$Base/mcp"; headers = @{ Authorization = "Bearer " + $t.access_token } } Set-Content -Path (Join-Path $dir "$($t.seat).token") -Value $t.access_token -NoNewline (@{ mcpServers = @{ consoleai = $entry } } | ConvertTo-Json -Depth 8) | Set-Content -Path (Join-Path $dir "$($t.seat).mcp.json") if ($Config) { $cfg = [ordered]@{} if (Test-Path $Config) { Copy-Item $Config "$Config.bak-consoleai" -Force; $cfg = Get-Content $Config -Raw | ConvertFrom-Json } if (-not $cfg.mcpServers) { $cfg | Add-Member -NotePropertyName mcpServers -NotePropertyValue ([pscustomobject]@{}) -Force } $cfg.mcpServers | Add-Member -NotePropertyName consoleai -NotePropertyValue ([pscustomobject]$entry) -Force ($cfg | ConvertTo-Json -Depth 12) | Set-Content -Path $Config Write-Host " merged into $Config as mcpServers.consoleai (backup: $Config.bak-consoleai)" } Write-Host "" Write-Host " Approved. Seat: $($t.seat) (member). Token saved (not shown), valid about $([int]($t.expires_in/86400)) days:" Write-Host " $dir\$($t.seat).token" Write-Host " $dir\$($t.seat).mcp.json (MCP server entry: $Base/mcp)" Write-Host " Restart the agent so it reloads its MCP servers."