This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 9a5bb07c Make `issued_token_type` optional to support OAuth2 Client 
Credential Flow (#466)
9a5bb07c is described below

commit 9a5bb07ca1a2ddda04310a23a2136fc6ae9a7515
Author: Yufei Gu <[email protected]>
AuthorDate: Thu Feb 29 03:39:27 2024 -0800

    Make `issued_token_type` optional to support OAuth2 Client Credential Flow 
(#466)
    
    * Make issued_token_type optional to support OAuth2 Client Credential Flow
    
    * Fix the style issue
    
    * Resolve comments
    
    * Resolve comments
    
    ---------
    
    Co-authored-by: yufei <[email protected]>
---
 pyiceberg/catalog/rest.py  |  6 ++++--
 tests/catalog/test_rest.py | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/pyiceberg/catalog/rest.py b/pyiceberg/catalog/rest.py
index 3132af9f..e0e88ec4 100644
--- a/pyiceberg/catalog/rest.py
+++ b/pyiceberg/catalog/rest.py
@@ -157,8 +157,10 @@ class RegisterTableRequest(IcebergBaseModel):
 class TokenResponse(IcebergBaseModel):
     access_token: str = Field()
     token_type: str = Field()
-    expires_in: int = Field()
-    issued_token_type: str = Field()
+    expires_in: Optional[int] = Field(default=None)
+    issued_token_type: Optional[str] = Field(default=None)
+    refresh_token: Optional[str] = Field(default=None)
+    scope: Optional[str] = Field(default=None)
 
 
 class ConfigResponse(IcebergBaseModel):
diff --git a/tests/catalog/test_rest.py b/tests/catalog/test_rest.py
index 21b4d955..c4668a71 100644
--- a/tests/catalog/test_rest.py
+++ b/tests/catalog/test_rest.py
@@ -108,6 +108,24 @@ def test_token_200(rest_mock: Mocker) -> None:
             "token_type": "Bearer",
             "expires_in": 86400,
             "issued_token_type": 
"urn:ietf:params:oauth:token-type:access_token",
+            "scope": "openid offline",
+            "refresh_token": "refresh_token",
+        },
+        status_code=200,
+        request_headers=OAUTH_TEST_HEADERS,
+    )
+    assert (
+        RestCatalog("rest", uri=TEST_URI, 
credential=TEST_CREDENTIALS)._session.headers["Authorization"]  # pylint: 
disable=W0212
+        == f"Bearer {TEST_TOKEN}"
+    )
+
+
+def test_token_200_without_optional_fields(rest_mock: Mocker) -> None:
+    rest_mock.post(
+        f"{TEST_URI}v1/oauth/tokens",
+        json={
+            "access_token": TEST_TOKEN,
+            "token_type": "Bearer",
         },
         status_code=200,
         request_headers=OAUTH_TEST_HEADERS,

Reply via email to