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", {}))