Skip to content

feat: add OAuth auth command with login, status, refresh and auto-401 retry - #37

Merged
aniket-s-kulkarni merged 4 commits into
dremio:mainfrom
aniket-s-kulkarni:oauth
Aug 25, 2026
Merged

feat: add OAuth auth command with login, status, refresh and auto-401 retry#37
aniket-s-kulkarni merged 4 commits into
dremio:mainfrom
aniket-s-kulkarni:oauth

Conversation

@aniket-s-kulkarni

Copy link
Copy Markdown
Collaborator

Summary

Add dremio auth command group for OAuth 2.0 PKCE authentication with Dremio Cloud, plus automatic 401 token refresh in the HTTP client.

New Commands

Command Description
dremio auth login Browser-based OAuth PKCE flow → stores access + refresh tokens
dremio auth status Shows auth method, JWT expiry, redacted token values
dremio auth refresh Manually refreshes the access token using stored refresh token
dremio auth logout Removes OAuth tokens from config

OAuth Configuration

  • Client ID: https://connectors.dremio.app/claude (default, overridable via --client-id)
  • Redirect URI: http://localhost:{port}/Callback
  • Scopes: dremio.all offline_access
  • Discovery: .well-known/oauth-authorization-server with hardcoded fallbacks for US/EU (/oauth/authorize path)

Automatic 401 Token Refresh

The DremioClient now intercepts 401 responses and transparently:

  1. Refreshes the access token using the stored OAuth refresh token + client ID
  2. Persists new tokens to ~/.config/dremioai/config.yaml
  3. Updates the in-memory httpx Authorization header
  4. Retries the original request once

A guard flag prevents infinite refresh loops (one attempt per client instance). If no OAuth config is present or refresh fails, the 401 propagates normally.

Auth Priority Chain (unchanged)

--token CLI arg → DREMIO_TOKEN env → oauth.access_token from config → pat field from config

New Modules

  • src/drs/oauth.py — PKCE flow, well-known discovery, token refresh
  • src/drs/commands/auth.py — typer command group

Tests

4 new tests for the 401 refresh logic:

  • 401 triggers refresh and retries with new token
  • 401 without OAuth config does not attempt refresh
  • Only one refresh attempt per client instance
  • Failed refresh propagates the original 401

Reference: modeled after dremio-mcp auth patterns

… retry

Add `dremio auth` command group with subcommands:
- `login`: browser-based OAuth 2.0 PKCE flow that stores access + refresh
  tokens in ~/.config/dremioai/config.yaml
- `status`: shows current auth method, token expiry (JWT decode), redacted
  token values
- `refresh`: manually refreshes the access token using stored refresh token
- `logout`: removes OAuth tokens from config

OAuth configuration:
- Client ID defaults to https://connectors.dremio.app/claude
- Redirect URI: http://localhost:{port}/Callback
- Scopes: dremio.all offline_access
- Endpoints discovered via .well-known/oauth-authorization-server with
  hardcoded fallbacks for US/EU regions using /oauth/authorize path

Automatic 401 token refresh in DremioClient:
- On any 401 response, if OAuth refresh_token + client_id are available,
  the client transparently refreshes the access token and retries once
- New tokens are persisted to disk and httpx headers updated in-place
- Guard flag prevents infinite refresh loops (one attempt per client instance)

Auth priority chain (unchanged): CLI --token > DREMIO_TOKEN env >
oauth.access_token from config > pat field from config

New modules:
- src/drs/oauth.py: PKCE flow, well-known discovery, token refresh
- src/drs/commands/auth.py: typer command group for auth subcommands

Tests: 4 new tests covering 401 refresh trigger, no-refresh without OAuth
config, single-attempt guard, and refresh failure propagation.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e41ed31c98

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/drs/auth.py Outdated
Comment thread src/drs/auth.py Outdated
Comment thread src/drs/client.py Outdated
Comment thread src/drs/client.py Outdated
…ath, transient retry

1. OAuth access_token now overrides file PAT (not just fills in when
   missing), so 'auth login' is effective even with an existing PAT from
   'setup'. (review comment #1)

2. Track auth_source on DrsConfig ('oauth'|'file'|'env'|'cli'). Auto-
   refresh only activates when auth_source == 'oauth', preventing the
   client from silently switching identity when --token or DREMIO_TOKEN
   supplies the active credential. (review comment dremio#2)

3. Store the effective config_path on DrsConfig and pass it through to
   save_oauth_tokens during auto-refresh, so custom --config paths get
   their tokens updated correctly. (review comment dremio#3)

4. After a successful 401 refresh, the retried response now falls through
   to the transient-status retry loop instead of returning immediately,
   so a post-refresh 429/503 is still retried. (review comment dremio#4)

Tests: 6 new tests (229 total) covering all four fixes.
@aniket-s-kulkarni
aniket-s-kulkarni merged commit c9391b1 into dremio:main Aug 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants