Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyiceberg/catalog/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class TokenResponse(IcebergBaseModel):
access_token: str = Field()
token_type: str = Field()
expires_in: int = Field()
issued_token_type: str = Field()
issued_token_type: Optional[str] = None
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we use this opportunity to align the OAuthTokenResponse exactly with the model specified in the Iceberg Rest Catalog Open API Spec?

  • we want to verify within the model that the issued_token_type is one of accepted types, if it is provided
  • the current model is missing Optional scope and refresh_token
  • also update expires_in to be Optional (expires_in is a recommended property in OAuth and if it wasn't provided in the TokenResponse, it will fail for similar reasons in the existing model)

Copy link
Copy Markdown
Contributor Author

@flyrain flyrain Feb 26, 2024

Choose a reason for hiding this comment

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

That's good ideas. Thanks for the review, @syun64. Fixed in a new commit.



class ConfigResponse(IcebergBaseModel):
Expand Down
17 changes: 17 additions & 0 deletions tests/catalog/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ def test_token_200(rest_mock: Mocker) -> None:
)


def test_token_200_without_issued_token_type(rest_mock: Mocker) -> None:
rest_mock.post(
f"{TEST_URI}v1/oauth/tokens",
json={
"access_token": TEST_TOKEN,
"token_type": "Bearer",
"expires_in": 86400,
},
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_w_auth_url(rest_mock: Mocker) -> None:
rest_mock.post(
TEST_AUTH_URL,
Expand Down