Add SSO support: two-round enforcement and pc target re-auth#86
Merged
austin-denoble merged 15 commits intomainfrom Apr 20, 2026
Merged
Add SSO support: two-round enforcement and pc target re-auth#86austin-denoble merged 15 commits intomainfrom
pc target re-auth#86austin-denoble merged 15 commits intomainfrom
Conversation
When authenticating into an organization that has SSO enforced, the CLI now passes the Auth0 connection name as a connection= parameter to the authorization endpoint, routing the browser directly to the org's identity provider rather than the generic login page. Both pc login and pc auth login accept a new --org flag to scope the login to a specific organization. pc target already passes the org ID implicitly. In all cases the SSO connection is resolved by calling the dashboard organizations API with the user's existing token; the lookup is best-effort and non-fatal — if it fails the flow falls back to the standard login page transparently.
…d targeting flows
…mplement finishAuthWithSSO and call in resumeSession, pollForResult, make sure getAndSetAccessTokenInteractive handles 2-step SSO properly
… before calling oauth.Logout()
…rly handles SSO, surfacing an error when an extra browser verification step is needed
…e login path, gracefull resume. prevent swallowing claims parsing error
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b9ea0ec. Configure here.
pc target re-auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
The CLI had no support for organizations with SSO enforced. Users in SSO-required orgs would land on the generic Auth0 login page instead of their identity provider, and authentication would either fail or succeed without proper SSO routing.
Solution
Core mechanism
Auth0 SSO routing requires a
connection=<name>parameter in the authorization URL. This PR adds a best-effort lookup of the connection name via the private dashboard organizations API (authenticated with the user's existing token), then passes it through to the PKCE auth URL. The lookup is non-fatal — if it fails or the org has no SSO configured, the flow falls back transparently to the standard login page.Two-round transparent enforcement
SSO enforcement is detected after round-1 authentication (once the token is available to query the dashboard API). When SSO is required, the CLI automatically starts a second login round with the
connection=parameter set, routing the browser to the org's IdP. This happens transparently in both flows:pc loginwithout--json): After code exchange, if SSO is enforced, the outer callback server's stdin-watching goroutine is cancelled before recursing into a fresh interactive round — preventing a goroutine race where the old goroutine could open the wrong URL on the next Enter keypress.pc login --json):finishAuthWithSSOis called when a session completes. If SSO is enforced, it cleans up the completed session eagerly (sofindResumableSessionwon't resurrect it), logs out, and starts a new daemon-backed session — emitting a newpendingJSON with the SSO URL for the agent to present.SessionStatecarries aSSOConnectionfield so round-2 sessions skip the enforcement check and don't loop."Already logged in" path
Run()now checks SSO enforcement before showing "already logged in". If SSO is required for the current org, the existing token is cleared and the SSO round starts immediately — covering the case where a user authenticates and SSO is later enabled for their org.Lazy auth completion (
EnsureAuthenticated)When a background daemon completes round-1 auth and the next CLI command triggers lazy completion,
EnsureAuthenticatednow checks SSO enforcement before handing off. If SSO is required, it leaves the session intact and directs the user topc loginto complete the SSO round, rather than silently proceeding with a non-SSO token.pc targetre-authBoth re-authentication sites in
pc targetnow resolve the SSO connection name before callingoauth.Logout(), so the lookup can use the still-valid token.Correctness fixes bundled in this PR
sess.OrgId == nil(previously would skip the mismatch check entirely)sess.OrgIdis nil (now defaults to"unknown")serverCtxusescontext.Background()as its base so the root command's 60s default timeout doesn't cut off a user mid-authenticationcontext.Background()for the same reasonType of Change
Test Plan
just test-unitpasses (includes new unit tests forGetAuthURLwithconnection=param andfetchSSOConnectionFromURLacross org-found, org-not-found, non-2xx, empty connection name, and multi-org cases)pc loginagainst an SSO-enforced org triggers round 2 automatically after round 1 completespc login --jsonpolling loop receivespending→ (SSO)pending→authenticatedpc target <sso-org>re-authenticates via SSO when switching orgsNote
Medium Risk
Touches the CLI OAuth login flow (interactive + daemon/JSON) and session resumption logic, which can affect all authentication paths. SSO lookup is best-effort and should fall back safely, but incorrect org/session handling could block logins.
Overview
Adds SSO-aware OAuth login by looking up an org's Auth0
connectionvia the dashboard API and injecting it into the authorization URL.Implements two-round SSO enforcement: after an initial login, the CLI detects
enforce_sso_authenticationand automatically restarts login using the resolvedconnection(both interactive and--jsondaemon flows), tracking round-2 state viaSessionState.SSOConnection.Updates
pc targetorg switching to resolve the SSO connection beforeoauth.Logout()and pass it intologin.GetAndSetAccessToken, and includes a few correctness fixes around session/org mismatch handling and timeouts during browser auth.Reviewed by Cursor Bugbot for commit f6e9247. Bugbot is set up for automated code reviews on this repo. Configure here.