Skip to content

Two-step device code login for environments that cannot wait for approval (login and add --connect-cloud) #858

Closed

Description

@mconflitti-pbc

Problem

Some agent environments run each shell command as a short call. Claude Cowork is one example:

  • A call ends after about 3 minutes.
  • The agent sees the output only when the call ends.
  • Child and background processes stop when the call ends.

rsconnect login --use-device-code and rsconnect add --connect-cloud print the verification URL and code, then poll for approval in the same process.
In these environments, the agent sees the code only after the call ends, which is too late to show it to the user.
The polling process then stops, so the login can never finish.

The device code flow is the correct flow for these environments, because it needs no localhost callback.
#842 asks rsconnect to fall back to the device code flow when the browser callback fails.
This issue asks for the next step: a device code login that works when the CLI cannot wait for approval.

Requested behavior

Split the device code flow into two commands. Each command exits immediately, or after a bounded wait.

# Posit Connect
rsconnect login https://connect.example.com --use-device-code --no-wait
#   prints the verification URL and user code, saves the pending login, exits
rsconnect login --finish [--timeout 120]
#   polls for up to --timeout seconds, then saves the credential like a normal login

# Posit Connect Cloud
rsconnect add --connect-cloud --account myteam --name cloud --no-wait
rsconnect add --finish [--timeout 120]

The flag names are only suggestions. Requirements:

  1. Save the pending login in the rsconnect-python config directory with owner-only permissions (0600). Never print the device code.
  2. If start runs again for the same target while a code is still valid, print the same link and code. Do not request a new code.
  3. Make the result machine-readable, for example a status word on the first line or distinct exit codes: pending (run finish again), failed (start again), or done.
  4. Keep the pending login while the code is still valid. Remove it when the code expires or the user denies it.
  5. Support both Posit Connect (login) and Posit Connect Cloud (add --connect-cloud).

Current workaround

We ship helper scripts in a Posit deploy skill for Claude Cowork that do this split with rsconnect-python internals.
For Posit Connect, they use rsconnect.oauth._poll_for_device_token, _unwrap_json_response, discover_oauth_metadata, register_client, keyring_store_token, and ServerStore.set.
For Posit Connect Cloud, they also use connect_cloud.urls, connect_cloud.client_id, connect_cloud.SCOPE, and connect_cloud.store_credentials_in_keyring.
The scripts work with 1.31.1, but private functions can change in any release.
A supported mode would let us remove the scripts.

The R rsconnect::connectCloudUser() has the same problem, but that belongs in the R package.

Activity

  1. added
    enhancement
    on Oct 7, 2026
  2. tdstein commented on Nov 10, 2026

    @tdstein
    Collaborator

    🤖 This shipped in 1.32.0 (#859). rsconnect login <server> --name <nick> --no-wait and rsconnect add --connect-cloud --account <acct> --name <nick> --no-wait start the device-code flow, print the verification URL and user code as JSON, and exit. rsconnect login --name <nick> --finish [--timeout 120] (or rsconnect add --connect-cloud --name <nick> --finish) completes the login later.

    • Pending state is stored with owner-only permissions.
    • Running start again while the code is valid returns the same code.
    • Results carry a status of pending or done.
    • The device code itself is never printed.

    Resumable login requires POSIX (Linux or macOS). This should let the Cowork helper scripts drop the private-function calls. If something in your workflow still needs the internals, please reopen with details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cloudenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions