Skip to content

Add WithExpiryDelta option to PersistentAuth#1532

Open
anthonyivn2 wants to merge 1 commit intodatabricks:mainfrom
anthonyivn2:add-expiry-delta
Open

Add WithExpiryDelta option to PersistentAuth#1532
anthonyivn2 wants to merge 1 commit intodatabricks:mainfrom
anthonyivn2:add-expiry-delta

Conversation

@anthonyivn2
Copy link

@anthonyivn2 anthonyivn2 commented Mar 11, 2026

Summary

  • Adds WithExpiryDelta(d time.Duration) option to PersistentAuth that configures a custom token expiry safety margin
  • When set, the token is considered expired if it has less than d remaining, triggering an early refresh
  • 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 databricks/cli#4564

Changes

  • credentials/u2m/persistent_auth.go: Added expiryDelta field, WithExpiryDelta option, tokenValid method, and updated Token() to use custom validity check
  • credentials/u2m/persistent_auth_test.go: Added 8 tests covering all edge cases (delta triggers/skips refresh, zero delta, zero expiry, nil/empty tokens)

Test plan

  • Unit tests for tokenValid with various delta/expiry combinations
  • Integration tests for Token() verifying refresh is triggered/skipped correctly
  • All existing tests in credentials/u2m/ pass

NO_CHANGELOG=true

anthonyivn2 added a commit to anthonyivn2/cli that referenced this pull request Mar 11, 2026
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
…xpiry margin

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. This adds a configurable safety margin so
the token is refreshed earlier when needed.

- Add `expiryDelta` field and `WithExpiryDelta` option function
- Add `tokenValid` method that uses the custom delta when set
- Force-expire token copy before refresh so oauth2 TokenSource performs
  the actual refresh even when the token has time left by its standards
@github-actions
Copy link

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-go

Inputs:

  • PR number: 1532
  • Commit SHA: ae24be866540044c21f246ad9ae0d59b4b9d324f

Checks will be approved automatically on success.

anthonyivn2 added a commit to anthonyivn2/cli that referenced this pull request Mar 11, 2026
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
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