-
Notifications
You must be signed in to change notification settings - Fork 33
[FEATURE] Adding token cache to u2m oauth #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java
Outdated
Show resolved
Hide resolved
| * @return The OAuth redirect URL to use | ||
| */ | ||
| public String getEffectiveOAuthRedirectUrl() { | ||
| return redirectUrl != null ? redirectUrl : "http://localhost:8080/callback"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is hardcoded at 2 places, making this error prone for future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i made this change to remove the hardcoded value from 2 places. where else do you mean is this hardcoded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we separate unrelated refactors such as this into separate PRs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually added code in ExternalBrowserCredentialsProvider where we would have to define this string "http://localhost:8080/callback" again without the refactor. Thought it would be in scope for this change?
databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java
Outdated
Show resolved
Hide resolved
...sdk-java/src/main/java/com/databricks/sdk/core/oauth/ExternalBrowserCredentialsProvider.java
Outdated
Show resolved
Hide resolved
mgyucht
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this seems like a nice contribution, left a few bits of feedback. Do we need to support disabling the cache & encrypting it? We don't have either of those features in the Python SDK and haven't heard any feedback/issues about this.
databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java
Outdated
Show resolved
Hide resolved
| * @return The OAuth redirect URL to use | ||
| */ | ||
| public String getEffectiveOAuthRedirectUrl() { | ||
| return redirectUrl != null ? redirectUrl : "http://localhost:8080/callback"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we separate unrelated refactors such as this into separate PRs?
| public HeaderFactory configure(DatabricksConfig config) { | ||
| if (config.getHost() == null || config.getAuthType() != "external-browser") { | ||
| if (config.getHost() == null | ||
| || config.getClientId() == null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? Are customers explicitly requesting external-browser but also configuring client IDs and that's causing issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the testing I did, we do need the client ID for external browser auth?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at how it is done in the Python SDK: https://github.com/databricks/databricks-sdk-py/blob/main/databricks/sdk/credentials_provider.py#L213-L220. Let's preserve that behavior, defaulting to databricks-cli if not set.
| } | ||
|
|
||
| @Test | ||
| void testDatabricksConfigDisabledTokenCache() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test belongs in DatabricksConfigTest, and we only need to test that the resulting token cache has caching disabled. (i.e. we can remove from line 198 onwards.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved
databricks-sdk-java/src/test/java/com/databricks/sdk/core/oauth/TokenCacheTest.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/test/java/com/databricks/sdk/core/oauth/TokenCacheTest.java
Outdated
Show resolved
Hide resolved
...java/src/test/java/com/databricks/sdk/core/oauth/ExternalBrowserCredentialsProviderTest.java
Outdated
Show resolved
Hide resolved
...java/src/test/java/com/databricks/sdk/core/oauth/ExternalBrowserCredentialsProviderTest.java
Show resolved
Hide resolved
| * | ||
| * @return A TokenCache instance | ||
| */ | ||
| public synchronized TokenCache getTokenCache() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just talking with @renaudhartert-db. Is it possible to inline this token cache entirely into ExternalBrowserCredentialsProvider? We're trying to break apart DatabricksConfig and stop using it as a dependency injection mechanism. I think you could do this by
- accepting the TokenCache as a constructor parameter in ExternalBrowserCredentialsProvider, falling back to this implementation if not specified
- Adding the token cache to SessionCredentials via its builder.
mgyucht
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion, otherwise this looks good to me!
| /** | ||
| * Resolves both client ID and client secret from the configuration. | ||
| * | ||
| * @param config The Databricks configuration | ||
| * @return An array containing the client ID and client secret (may be null) | ||
| */ | ||
| public static String[] resolveClientCredentials(DatabricksConfig config) { | ||
| String clientId = resolveClientId(config); | ||
| String clientSecret = resolveClientSecret(config); | ||
| return new String[] {clientId, clientSecret}; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really necessary? I think callers can just call resolveClientId() and resolveClientSecret() as needed.
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
What changes are proposed in this pull request?
What: Introduce a token cache to be used in browser based u2m oauth
Why: Makes user experience better by using valid access/refresh tokens from the cache instead of requiring a new browser auth
How is this tested?
In addition to the unit tests,
Manual testing: