-
Notifications
You must be signed in to change notification settings - Fork 167
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
added support for OAuth Client Credentials grant in the Scala client #553
added support for OAuth Client Credentials grant in the Scala client #553
Conversation
client/src/main/scala/io/delta/sharing/client/DeltaSharingClient.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingProfileProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingProfileProvider.scala
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingProfileProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingProfileProvider.scala
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/auth/CredentialProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/auth/CredentialProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/auth/OAuthClient.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingClient.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingClient.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingProfileProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingProfileProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingProfileProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingClient.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingProfileProvider.scala
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingProfileProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/DeltaSharingProfileProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/auth/OAuthClient.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/auth/OAuthClientCredentialsAuthProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/auth/OAuthClientCredentialsAuthProvider.scala
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/auth/OAuthClientCredentialsAuthProvider.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/auth/OAuthClientCredentialsAuthProvider.scala
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/auth/OAuthClientCredentialsAuthProvider.scala
Outdated
Show resolved
Hide resolved
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.
Almost looking good, I still need some time to read OAuth* changes.
client/src/main/scala/io/delta/sharing/client/auth/OAuthClientCredentialsAuthProvider.scala
Outdated
Show resolved
Hide resolved
… now I changed to re-entrant lock for better readiblity
client/src/main/scala/io/delta/sharing/client/auth/OAuthClientCredentialsAuthProvider.scala
Show resolved
Hide resolved
client/src/test/scala/io/delta/sharing/client/DeltaSharingFileProfileProviderSuite.scala
Outdated
Show resolved
Hide resolved
client/src/main/scala/io/delta/sharing/client/auth/OAuthClientCredentialsAuthProvider.scala
Outdated
Show resolved
Hide resolved
case oauthProfile: OAuthClientCredentialsDeltaSharingProfile => | ||
OAuthClientCredentialsAuthProvider(client, authConfig, oauthProfile) | ||
case BearerTokenDeltaSharingProfile(_, _, bearerToken, expirationTime) => | ||
BearerTokenAuthProvider(bearerToken, expirationTime) |
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.
nit: should we throw internal exception if it didn't match either.
maxDur | ||
} | ||
|
||
def tokenRenewalThresholdInSeconds(conf: Configuration): Int = { |
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.
we may not need both functions for each conf?
The current OAuth implementation in the Python client does not reuse access tokens. Instead, it exchanges the client-id and client-secret for a new access token with every request. This behavior increases the load on the tokenEndpoint and introduces unnecessary latency in the request processing. This PR updates the OAuth implementation to oauth reuse access tokens, aligning the Python client with the OAuth behavior of the Scala client, as detailed in this [PR for the Scala client](#553). For additional context on the usage of auth_provider and its functionality, please refer to the description in the original PR for the Spark client.
Added OAuth Client Credentials Support in Scala Client
Overview:
This PR introduces support for OAuth Client Credentials in the Scala client.
Adds a CredentialProvider trait and two implementations:
CredentialProvider
Trait:Added the CredentialProvider trait which includes a method CredentialProvider#addAuthHeader(httpRequest: HttpRequestBase). This method is responsible for adding the authentication header to the HTTP request.
Implementations of CredentialProvider:
BearerTokenAuthProvider
: A simple implementation that uses a provided bearer token.OAuthClientCredentialsAuthProvider
: This implementation handles OAuth client credential grants. It manages the access token internally and refreshes it when it is about to expire (within the next 10 minutes), using the clientId and clientSecret to obtain a new token.Functionality:
The DeltaShringClient now invokes credentialProvider.addAuthHeader() before making any requests, ensuring that the appropriate authentication header is included.
OAuth Token Management:
The OAuthClientCredentialsAuthProvider efficiently manages the OAuth access token. It only exchanges the clientId and clientSecret for a new access token when the current token is nearing expiration
New format for the profile share file: