Skip to content

Commit

Permalink
corrected after the review
Browse files Browse the repository at this point in the history
  • Loading branch information
bazarnov committed Dec 19, 2024
1 parent 63d4f42 commit 028f0c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions airbyte_cdk/sources/declarative/auth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DeclarativeOauth2Authenticator(AbstractOauth2Authenticator, DeclarativeAut
token_expiry_date_format: Optional[str] = None
token_expiry_is_time_of_expiration: bool = False
access_token_name: Union[InterpolatedString, str] = "access_token"
access_token_value: Optional[str] = None
access_token_value: Optional[Union[InterpolatedString, str]] = None
expires_in_name: Union[InterpolatedString, str] = "expires_in"
refresh_request_body: Optional[Mapping[str, Any]] = None
grant_type: Union[InterpolatedString, str] = "refresh_token"
Expand Down Expand Up @@ -96,8 +96,15 @@ def __post_init__(self, parameters: Mapping[str, Any]) -> None:
if self.token_expiry_date
else pendulum.now().subtract(days=1) # type: ignore # substract does not have type hints
)
if self.access_token_value is not None:
self._access_token_value = InterpolatedString.create(
self.access_token_value, parameters=parameters
).eval(self.config)
else:
self._access_token_value = None

self._access_token: Optional[str] = (
self.access_token_value if self.access_token_value else None
self._access_token_value if self.access_token_value else None
)

if self.get_grant_type() == "refresh_token" and self._refresh_token is None:
Expand Down
6 changes: 3 additions & 3 deletions unit_tests/sources/declarative/auth/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"custom_field": "in_outbound_request",
"another_field": "exists_in_body",
"grant_type": "some_grant_type",
"access_token": "some_access_token",
}
parameters = {"refresh_token": "some_refresh_token"}

Expand Down Expand Up @@ -138,15 +139,14 @@ def test_get_auth_header_without_refresh_token_and_without_refresh_token_endpoin
contains the authentication.
"""
oauth = DeclarativeOauth2Authenticator(
access_token_value="my_access_token_value",
access_token_value="{{ config['access_token'] }}",
client_id="{{ config['client_id'] }}",
client_secret="{{ config['client_secret'] }}",
config=config,
parameters={},
grant_type="client_credentials",
)

assert oauth.get_auth_header() == {"Authorization": "Bearer my_access_token_value"}
assert oauth.get_auth_header() == {"Authorization": "Bearer some_access_token"}

def test_error_on_refresh_token_grant_without_refresh_token(self):
"""
Expand Down

0 comments on commit 028f0c1

Please sign in to comment.