Skip to content

Add --refresh-before flag to databricks auth token#4699

Open
anthonyivn2 wants to merge 1 commit intodatabricks:mainfrom
anthonyivn2:add-refresh-before-flag
Open

Add --refresh-before flag to databricks auth token#4699
anthonyivn2 wants to merge 1 commit intodatabricks:mainfrom
anthonyivn2:add-refresh-before-flag

Conversation

@anthonyivn2
Copy link

Summary

  • Adds --refresh-before flag to databricks auth token (e.g., --refresh-before 5m) that refreshes the token if it expires within the given duration
  • Fixes the issue where users of databricks auth token as an API key helper (e.g., for Claude Code) get expired tokens because oauth2's default ~10-second expiry window is too short

Resolves #4564

Depends on SDK PR: databricks/databricks-sdk-go#1532

Note: The go.mod currently contains a replace directive pointing to a local SDK with the WithExpiryDelta change. Once the SDK PR is merged and released, this will be replaced with a proper version bump.

Changes

  • cmd/auth/token.go: Added --refresh-before flag, refreshBefore field in loadTokenArgs, wired u2m.WithExpiryDelta
  • cmd/auth/token_test.go: Added 3 test cases (forces refresh, skips refresh, zero preserves default)

Test plan

  • refreshBefore forces refresh when token expires within window (2h delta, 1h token)
  • refreshBefore skips refresh when token has enough time (5m delta, 1h token)
  • refreshBefore: 0 preserves default behavior
  • All existing TestToken_loadToken tests pass (31/31)
  • Drop replace directive after SDK release and verify CI passes

Users who use `databricks auth token` as an API key helper (e.g., for
Claude Code) get expired tokens because the oauth2 library only refreshes
within ~10 seconds of expiry. The new `--refresh-before` flag (e.g.,
`--refresh-before 5m`) refreshes the token if it expires within the
given window.

Depends on: databricks/databricks-sdk-go#1532

Resolves databricks#4564
@anthonyivn2 anthonyivn2 force-pushed the add-refresh-before-flag branch from d889a33 to 5f4bc44 Compare March 11, 2026 02:26
@github-actions
Copy link

An authorized user can trigger integration tests manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 4699
  • Commit SHA: 5f4bc44c5e03da7ddcbab6be8961d6531c29f30c

Checks will be approved automatically on success.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please support customizing expiryDelta for auth token command

1 participant