Repository navigation
Replies: 1 comment
|
Implementation PR against plugin-auth, adding |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
Please add a way to complete
sf org login webwhen the machine running the CLI has no browser: print the authorization URL, let the developer log in from a browser on any other device, and accept the resulting callback URL pasted back into the same waiting command. Something like:The flag name is open for discussion. No new server-side API is needed: the flow is the existing Authorization Code + PKCE web server flow with the existing
PlatformCLIconnected app. The only change is how the CLI receives the redirect: from stdin instead of from a local HTTP listener.A working proof of concept exists as a standalone plugin: https://github.com/Damecek/sf-plugin-remote-login (
sf org login remote). It was verified end to end from a headless Docker container with the login completed on an iPhone. Details below.Why this matters now
Developer workflows have changed. A growing share of development work is delegated to autonomous coding agents that run on remote Linux hosts, containers, home servers or cloud dev environments. The developer talks to the agent from a phone, a web UI or an SSH session. The agent has a terminal but no desktop and no browser. Today, when such an agent needs a Salesforce org it has not been authenticated to,
sf org login webcannot finish, and the developer has to switch to a machine with a desktop just to authorize the CLI.Human approval stays in the loop. This is not a request to bypass or weaken anything. The developer still goes through the normal Salesforce login page in a trusted browser, including SSO, MFA, IP restrictions and connected-app policies. The only difference from today is that the browser is on a different device than the CLI.
JWT is not an equivalent replacement. JWT bearer auth is the right tool for unattended, pre-configured automation. For an ad hoc development session it requires creating a connected app, a certificate, pre-authorizing profiles, and distributing a private key to the agent host, per org, before the first login. The scenario here is the opposite: a human wants to grant an agent access to an org right now, with nothing prepared.
Device Flow is not being asked for. We understand why
org login devicewas removed (#3368: restrictions on uninstalled connected apps and the Device Flow policy on the default app). The proposed flow is the supported web server flow with PKCE, which #3668 just made mandatory onPlatformCLI. It does not need Device Flow to be re-enabled.Remote and mobile-first. The flow works from an iPhone, a tablet, a browser-based IDE, a container, or an SSH session, because the only thing that has to move between devices is two URLs.
Proposed behaviour
AuthInfo.getAuthorizationUrlwith a jsforceOAuth2instance that holds the PKCE verifier, randomstate,prompt=login, default scopes,redirect_uri=http://localhost:1717/OauthRedirect).open()and startingWebOAuthServer, it prints the URL and short instructions, then waits on a hidden prompt (secretPrompt).http://localhost:1717/OauthRedirect?code=...&state=..., which does not load on that device. That is fine: the code is in the address bar. The developer copies the address and pastes it into the waiting command.stateequal to the one it generated (constant-time compare), noerrorparameter,codepresent.AuthInfo.create({ oauth2Options: { ...config, authCode }, oauth2 })exchanges the code with the original PKCE verifier,AuthInfo.save()persists it,handleAliasAndDefaultSettingsapplies--alias,--set-default,--set-default-dev-hub. Output and--jsonare the same as today.Everything after step 3 is existing
@salesforce/corecode. In the proof of concept the whole feature is about 150 lines including messages, with no new dependencies beyond whatplugin-authalready uses.Proof of concept
Repository: https://github.com/Damecek/sf-plugin-remote-login (MIT)
Install and use:
What was verified (full log in the repo's
VERIFICATION.md):node:22-bookworm-slim, noDISPLAY, no X socket, no browser binaries, command run under a pseudo-terminal. The plugin was installed from the git URL withsf plugins install.login.salesforce.com. Safari showed "cannot open the page" for the localhost redirect; the full URL was copied from the address bar.Successfully authorized <user> with org ID <id>. Afterwards, in the same container and using only the stored auth:sf org list auth(Auth Method: web),sf org display(Connected),sf data query --query "SELECT Id FROM User LIMIT 1"(1 record). The auth file has the same fields as one written byorg login web.sffrom the commit.Not verified: SSO logins (same flow as
org login web, but not exercised), Android browsers, Code Builder.Security considerations
org login web. PKCE verifier andstateare random, held in memory, never printed.--json. The authorization code is single use, short lived, and useless without the PKCE verifier held by the waiting process.state, OAutherrorsurfaced, missing code rejected.localhost:1717could today.One honest trade-off: copying a long URL by hand is clunky, and the "cannot connect" page after login looks like an error until you have read the instructions. A dedicated redirect page that just displays the URL to copy would improve this, but it is not required.
Relation to earlier threads
sf org login webdoes not work whenSF_CONTAINER_MODEis set to true #3415 reported thatorg login webfails in containers; the answer was that headless web login is not supported.localhoston the CLI machine. This proposal adds the missing half (accepting the redirect URL from stdin) and shows it working against the current PKCE-mandatoryPlatformCLIapp.Salesforce CLIconnected app #3368 explains the Device Flow removal; this proposal does not depend on Device Flow.Happy to turn the proof of concept into a PR against
plugin-authif the team is open to the idea.All reactions