From f51612eabc20504b75741b37f14a228daa095098 Mon Sep 17 00:00:00 2001 From: Steve Clarke <84364906+s7clarke10@users.noreply.github.com> Date: Thu, 5 Sep 2024 02:37:25 +1200 Subject: [PATCH] Fixing oauth tap auth due to sdk framework change (#58) --- tap_rest_api_msdk/auth.py | 10 ++++++++++ tap_rest_api_msdk/tap.py | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/tap_rest_api_msdk/auth.py b/tap_rest_api_msdk/auth.py index e54abab..d2304ac 100644 --- a/tap_rest_api_msdk/auth.py +++ b/tap_rest_api_msdk/auth.py @@ -116,6 +116,16 @@ def get_aws_session_client(self): class ConfigurableOAuthAuthenticator(OAuthAuthenticator): """Configurable OAuth Authenticator.""" + + def get_initial_oauth_token(self): + """Gets a oauth token for the tap schema discovery. + + Requests an oauth token and sets the auth headers. + """ + if not self.is_token_valid(): + self.update_access_token() + + self.auth_headers["Authorization"] = f"Bearer {self.access_token}" @property def oauth_request_body(self) -> dict: diff --git a/tap_rest_api_msdk/tap.py b/tap_rest_api_msdk/tap.py index af6e861..2524d17 100644 --- a/tap_rest_api_msdk/tap.py +++ b/tap_rest_api_msdk/tap.py @@ -582,6 +582,10 @@ def get_schema( # Obtaining Authenticator for authorisation to obtain a schema. get_authenticator(self) + # Get an initial oauth token if an oauth method + if auth_method == 'oauth': + self._authenticator.get_initial_oauth_token() + headers.update(getattr(self._authenticator, "auth_headers", {})) params.update(getattr(self._authenticator, "auth_params", {}))