Skip to content

CLI: session expires after ~1 hour due to OAuth client_id mismatch on token refresh #63

Closed

Description

@tijs

Problem

When using the CLI, sessions expire after approximately 1 hour. Running any command after that shows "Not logged in" even though the user previously authenticated successfully.

Root cause

The OAuth client_id for loopback clients includes the redirect URI with the port number. During sb login, a random free port is used (e.g., 54321), producing a client_id like:

http://localhost?redirect_uri=http%3A%2F%2F127.0.0.1%3A54321%2Fcallback&scope=...

When restoring sessions in getAgent(), a hardcoded port 0 is used instead:

http://localhost?redirect_uri=http%3A%2F%2F127.0.0.1%3A0%2Fcallback&scope=...

This produces a different client_id. When the access token expires (~1 hour TTL from the PDS) and the OAuth library tries to use the refresh token, the PDS rejects the request because the client_id doesn't match the one used during authorization.

Steps to reproduce

  1. sb login <handle> — authenticate via browser
  2. Use any command (e.g., sb cards) — works fine
  3. Wait ~1 hour for the access token to expire
  4. Run any command again — fails with "Not logged in"

Fix

Store the port used during login in session.json and reuse it when creating the NodeOAuthClient for session restoration. This keeps the client_id consistent so token refresh works correctly.

PR: #64

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions