Skip to content

New OAuth2AuthManager #2244

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

New OAuth2AuthManager #2244

wants to merge 16 commits into from

Conversation

sungwy
Copy link
Collaborator

@sungwy sungwy commented Jul 23, 2025

Rationale for this change

New OAuth2Manager implementation that makes use of AuthManager and more closely follows https://datatracker.ietf.org/doc/html/rfc6749 recommendations. It injects the encoded secret into the Basic header against the authentication server, as recommended by the RFC instead of injecting it into the request body, which is less secure.

Proactively refreshes the access token by checking the expiration.

Are these changes tested?

Yes, both in unit and integration tests.

Are there any user-facing changes?

No, this is a new feature.

Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, a few nit comments. Lets get #2055 merged and then rebase this PR

return self._token


class OAuth2AuthManager(AuthManager):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have any tests for LegacyOAuth2AuthManager? do we want OAuth2AuthManager to be feature parity in this first release?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont see credential, resource, and audience

| credential | client_id:client_secret | Credential to use for OAuth2 credential flow when initializing the catalog |
| scope | openid offline corpds:ds:profile | Desired scope of the requested security token (default : catalog) |
| resource | rest_catalog.iceberg.com | URI for the target resource or service |
| audience | rest_catalog | Logical name of target resource or service |

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are using client_id and client_secret instead in the current implementation, as opposed to credential. This is also currently in draft mode, and I intend to review OAuth2 spec a little bit more in depth and other industry standard implementations before finalizing the implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I researched the IETF RFCs on OAuth closely, and my understanding is that resource and audience parameters were introduced in subsequent RFCs as supplemental parameters. What do you think about merging this version of the OAuth2AuthManager that closely follows the initial RFC6749 and introducing those as followup PRs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense! thanks for looking into it

@kevinjqliu
Copy link
Contributor

i took the liberty to merge main :)

@kevinjqliu kevinjqliu added this to the PyIceberg 0.10.0 milestone Jul 25, 2025
@kevinjqliu kevinjqliu requested a review from Copilot July 25, 2025 23:49
Copilot

This comment was marked as outdated.

@kevinjqliu kevinjqliu requested a review from Copilot July 26, 2025 00:19
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new OAuth2Manager implementation that more closely follows RFC6749 standards, replacing the legacy OAuth2 implementation. The new implementation includes proactive token refresh capabilities based on expiration times.

  • Adds a new OAuth2AuthManager with RFC6749-compliant implementation
  • Introduces thread-safe OAuth2TokenProvider for token management with automatic refresh
  • Updates documentation to reflect the new oauth2 auth type and deprecates legacyoauth2

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pyiceberg/catalog/rest/auth.py Implements OAuth2TokenProvider and OAuth2AuthManager classes with thread-safe token refresh
tests/catalog/test_rest.py Adds integration test for the new oauth2 authentication type
mkdocs/docs/configuration.md Updates documentation to include oauth2 configuration and marks legacyoauth2 as deprecated

@sungwy sungwy marked this pull request as ready for review August 14, 2025 03:08
@sungwy sungwy changed the title New OAuth2Manager New OAuth2AuthManager Aug 14, 2025
@sungwy sungwy requested a review from Fokko August 14, 2025 13:14
Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

With this change,

        data = {
            "grant_type": "client_credentials"
        }

I was able to verify locally with Microsoft Entra, which is also an Oauth2 provider :)

return self._token


class OAuth2AuthManager(AuthManager):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense! thanks for looking into it

sungwy and others added 2 commits August 14, 2025 21:46
Co-authored-by: Kevin Liu <[email protected]>
Co-authored-by: Kevin Liu <[email protected]>
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.

4 participants