Ensure that refresh tokens are returned when using the external-browser credentials strategy
#931
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes are proposed in this pull request?
Today, the
external-browsercredentials strategy allows users to dynamically fetch an OAuth token without depending on external tools like the Databricks CLI. However, the requested scope is hard-coded to always beall-apis. As a result, after successfully authenticating, the authorization server will return only an access token and no refresh token. The access token will expire after an hour, and attempts to refresh the token will fail.This PR adds the
offline_accessscope to the default requested scopes during this flow. This matches the request made by the CLI in thedatabricks auth loginflow. The resulting token includes a refresh token.How is this tested?
I manually tested this by deleting the token cache at
~/.config/databricks-sdk-py/oauthand then running the following script:The resulting token is saved to the OAuth cache. This token includes the refresh token.
To force a refresh, I manually updated the expiry time to be in the past and reran the script. The token was refreshed and the script succeeded: