Skip to main content
Sentry CLI uses OAuth 2.0 device flow (RFC 8628) for secure authentication without requiring a browser redirect. Tokens are stored locally in SQLite with automatic refresh support.

Authentication Methods

The CLI supports three authentication methods, checked in this priority order:
  1. SENTRY_AUTH_TOKEN environment variable (highest priority)
  2. SENTRY_TOKEN environment variable (legacy)
  3. OAuth tokens stored in SQLite (lowest priority)

Environment Variable Authentication

The simplest way to authenticate is via environment variables:
Tokens from environment variables:
  • Bypass all expiry and refresh logic
  • Are never written to disk
  • Take priority over stored OAuth tokens
  • Empty or whitespace-only values are treated as unset
SENTRY_AUTH_TOKEN takes precedence over SENTRY_TOKEN to match the legacy sentry-cli behavior.

OAuth Device Flow

The recommended authentication method is OAuth device flow:
This initiates the device authorization flow:
  1. CLI requests a device code from Sentry’s /oauth/device/code/ endpoint
  2. CLI displays a user code and verification URL
  3. User visits the URL and enters the code (or scans QR code)
  4. CLI polls /oauth/token/ endpoint until user completes authorization
  5. Access token and refresh token are stored in SQLite

Device Flow Implementation

The device flow is implemented in src/lib/oauth.ts:

OAuth Scopes

The CLI requests the following scopes:
  • project:read - Read project data
  • project:write - Write project data
  • org:read - Read organization data
  • event:read - Read events
  • event:write - Write events
  • member:read - Read organization members
  • team:read - Read team data

Token Storage

OAuth tokens are stored in SQLite at ~/.sentry/config.db:
The auth table uses a single-row pattern (always id = 1) to store the active credential.

Token Retrieval Priority

The getAuthToken() function checks sources in priority order:

Automatic Token Refresh

OAuth tokens are automatically refreshed when:
  • Less than 10% of the token’s lifetime remains (default threshold)
  • A 401 Unauthorized response is received from the API
  • Forced via sentry auth refresh

Refresh Flow

The refresh flow is implemented in src/lib/db/auth.ts:
Token refresh uses a singleton promise to prevent concurrent refresh attempts during parallel API calls.

Self-Hosted Sentry

For self-hosted Sentry instances, configure both URL and client ID:

Creating an OAuth App

To use OAuth with self-hosted Sentry (requires 26.1.0+):
  1. Navigate to Settings → Developer Settings in your Sentry instance
  2. Create a new public OAuth application
  3. Copy the Client ID
  4. Set SENTRY_CLIENT_ID environment variable
OAuth device flow requires Sentry 26.1.0 or later. For older versions, use sentry auth login --token with an API token instead.

Configuration Resolution

The CLI reads configuration lazily (not at module load) to respect environment variables set after import:
This allows URL parsing from command arguments to set SENTRY_URL before the OAuth flow begins.

Authentication State Commands

Check Status

Shows the current authentication state and token source.

Manual Refresh

Forces a token refresh even if the current token hasn’t expired.

Logout

Clears stored tokens and related cached data:
  • Auth tokens
  • User info cache
  • Organization region cache
  • Pagination cursors
Logging out only clears SQLite-stored tokens. Environment variable tokens remain active.

Token Source Tracking

The CLI tracks where each token originated via the AuthSource type:
This allows commands to conditionally skip refresh logic for environment tokens and provide accurate status messages.

Error Handling

Authentication errors use the AuthError class with specific reason codes:
The CLI automatically triggers the login flow when AuthError is thrown, providing a seamless authentication experience.