Skip to content

Linear OAuth tokens expire after 24h - missing proper refresh token flow implementation #285

@gudzenkov

Description

@gudzenkov

Problem Description

Linear OAuth access tokens expire after 24 hours, but Cyrus does not implement the proper refresh token flow as documented in the Linear OAuth 2.0 documentation. This causes authentication failures and requires manual re-authorization daily.

Current Behavior

  • Linear OAuth tokens (LINEAR_OAUTH_TOKEN) expire after 24 hours
  • When tokens expire, Cyrus fails with authentication errors
  • Users must manually re-authorize to continue using Cyrus
  • No automatic refresh token mechanism is implemented

Expected Behavior

According to Linear's OAuth documentation, Cyrus should:

  1. Store the refresh_token received during initial authorization
  2. When receiving a 401 error or detecting token expiration, automatically use the refresh token to obtain a new access token
  3. Update the stored access token with the new one
  4. Continue operations without user intervention

Steps to Reproduce

  1. Set up self-hosted Cyrus App with Linear OAuth authentication
  2. Deploy CloudFlare Worker Proxy
  3. Run local Cyrus CLI, authorize with Linear OAuth
  4. Wait 24 hours for the token to expire
  5. Attempt to run Cyrus with the expired token
  6. Observe authentication failure requiring manual re-authorization
EdgeWorker error: Error: Linear authentication failed for Portfolio. The Linear OAuth token may have expired or been revoked. Please re-authenticate with Linear to obtain a new token.
    at WebhookTransport.registerWebhook (file:///opt/cyrus/packages/ndjson-client/dist/transports/WebhookTransport.js:137:39)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  code: 'LINEAR_AUTH_FAILED',
  isAuthError: true
}

❌ Linear authentication failed for repository: sandbox
   Workspace: 18544a12-e52c-4e40-81e1-766e0c46650e
   Error: Linear authentication failed for Portfolio. The Linear OAuth token may have expired or been revoked. Please re-authenticate with Linear to obtain a new token.

   To fix this issue:
   1. Run: cyrus refresh-token
   2. Complete the OAuth flow in your browser
   3. The configuration will be automatically updated

❌ Failed to start edge application: Failed to connect any repositories. Please check your configuration and Linear tokens.

Technical Details

The Linear API refresh token flow requires:

POST https://api.linear.app/oauth/token
Content-Type: application/json

{
  "grant_type": "refresh_token",
  "refresh_token": "<stored_refresh_token>",
  "client_id": "<client_id>",
  "client_secret": "<client_secret>"
}

Impact

  • Daily manual re-authorization disrupts automated workflows
  • Breaks continuous integration/deployment pipelines
  • Reduces the reliability of Cyrus as an automation tool

Related Issues

Suggested Solution

Implement automatic refresh token handling:

  1. Store refresh tokens securely alongside access tokens
  2. Implement token refresh logic before API calls or on 401 responses
  3. Automatically retry failed requests after token refresh
  4. Only require user re-authorization if refresh token is invalid/expired

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions