feat: Add connection test command for SSO login flow#177
feat: Add connection test command for SSO login flow#177jonatascastro12 wants to merge 5 commits into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Original prompt from jonatas
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Greptile SummaryThis PR adds
Confidence Score: 4/5Safe to merge after fixing the agent-mode browser-open guard — in its current state the command will hang indefinitely when run from agent environments like Claude Code, Cursor, or Codex. The browser auto-open guard checks only for CI mode, not agent mode. Since CI and agent are distinct modes in this codebase, isCiMode() returns false when WORKOS_AGENT, CLAUDE_CODE, or similar environment markers are set. The command will call open(), silently swallow the error, then block on callbackPromise for the full timeout (default 5 minutes) before surfacing any failure. All other aspects — state validation, server lifecycle, code exchange, redirect URI registration fallback, and JSON output — are correct and well-tested. src/commands/connection.ts — the browser-open guard at line 283 needs to also check isAgentMode(). Important Files Changed
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Summary
Adds
workos connection test <id>— an end-to-end SSO smoke test for a connection, run entirely from the CLI:http://localhost:<port>/callbackas an environment redirect URI automatically via the existingPOST /user_management/redirect_uriswrapper (client.redirectUris.add). If registration fails (e.g. insufficient permissions), it prints the URI and asks the user to add it in the Dashboard before continuing (errors out in agent/CI mode instead of prompting).sso.getAuthorizationUrl({ clientId, redirectUri, connection, state }), whereclientIdresolves from--client-id→WORKOS_CLIENT_ID→ the active environment's stored client ID.--no-opento disable), waits for the IdP redirect (default 300s timeout,--timeoutto override), validatesstate, exchanges the code viasso.getProfileAndToken, and prints the authenticated profile.Flags:
--client-id,--port(default 4807),--timeout,--open/--no-open, plus the usual--api-key/--json.JSON mode outputs
{ connectionId, redirectUri, redirectUriRegistered, authorizationUrl, profile }.Also registered in
bin.tsand thehelp-json.tscommand registry, with spec coverage for the happy path, flag overrides, IdP error callbacks, state mismatch, registration fallback prompts, agent-mode behavior, and JSON output.Test plan
pnpm test(2102 passed),pnpm typecheck,pnpm lint,pnpm format:check,pnpm buildall passsrc/commands/connection.spec.tsmock the HTTP server, browser open, and SDK to exercise the full callback flowLink to Devin session: https://app.devin.ai/sessions/68e059345eaa4022851eb4f324d9c361
Requested by: @jonatascastro12