Skip to content

Commit

Permalink
Make issued_token_type optional to support OAuth2 Client Credential…
Browse files Browse the repository at this point in the history
… Flow (apache#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]>
  • Loading branch information
2 people authored and hpal committed Mar 1, 2024
1 parent 29f1c04 commit 83b34bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pyiceberg/catalog/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 18 additions & 0 deletions tests/catalog/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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,
Expand Down

0 comments on commit 83b34bb

Please sign in to comment.