Skip to content
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

Merged

Conversation

moderakh
Copy link
Collaborator

@moderakh moderakh commented Aug 5, 2024

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:

  • BearerTokenAuthProvider and OAuthClientCredentialsAuthProvider.

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:

{
    "shareCredentialsVersion": 2,
    "type": "oauth_client_credentials",
    "endpoint": "https://example.com/delta-sharing/",
    "tokenEndpoint": "https://example.com/oauth/v1/token",
    "clientId": "ABCE",
    "clientSecret": "XYZE",
    "scope" : "abc" // optional parameter
}

@moderakh moderakh changed the title added support for OAuth Client Credentials in the Scala client added support for OAuth Client Credentials grant in the Scala client Aug 5, 2024
Copy link
Collaborator

@linzhou-db linzhou-db left a 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.

@moderakh moderakh merged commit 830196e into delta-io:main Aug 8, 2024
5 checks passed
case oauthProfile: OAuthClientCredentialsDeltaSharingProfile =>
OAuthClientCredentialsAuthProvider(client, authConfig, oauthProfile)
case BearerTokenDeltaSharingProfile(_, _, bearerToken, expirationTime) =>
BearerTokenAuthProvider(bearerToken, expirationTime)
Copy link
Collaborator

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 = {
Copy link
Collaborator

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?

moderakh added a commit that referenced this pull request Aug 14, 2024
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.
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.

3 participants