alex_dimov
11/24/2022, 10:42 AMclient.py
I overridden the http_headers function
@property
def http_headers(self) -> dict:
"""Return the http headers needed."""
headers = {}
if "user_agent" in self.config:
headers["User-Agent"] = self.config.get("user_agent")
if "client_id" in self.config:
headers["ClientId"] = self.config.get("client_id")
# If not using an authenticator, you may also provide inline auth headers:
# headers["Private-Token"] = self.config.get("auth_token")
return headers
I expected that on a request to get a token using the OAuthAuthenticator class, headers["ClientId"] would be automatically added to the request, but now this does not happenReuben (Matatika)
11/24/2022, 10:58 AMRESTStream.http_headers
says
If an authenticator is also specified, the authenticator's headers will be combined withHere is that logic: https://github.com/meltano/sdk/blob/7962ebc9a9a0ff14e77e6aeb1b76d8e5cda2bc73/singer_sdk/streams/rest.py#L274-L301when making HTTP requests.http_headers
Reuben (Matatika)
11/24/2022, 11:13 AMClientId
header?alex_dimov
11/24/2022, 11:13 AMalex_dimov
11/24/2022, 11:15 AMalex_dimov
11/24/2022, 11:16 AMReuben (Matatika)
11/24/2022, 11:17 AMalex_dimov
11/24/2022, 11:18 AMReuben (Matatika)
11/24/2022, 11:18 AMClientId
header?alex_dimov
11/24/2022, 11:18 AMalex_dimov
11/24/2022, 11:19 AMReuben (Matatika)
11/24/2022, 11:19 AMalex_dimov
11/24/2022, 11:19 AMReuben (Matatika)
11/24/2022, 11:19 AMalex_dimov
11/24/2022, 11:20 AMReuben (Matatika)
11/24/2022, 11:22 AMauth.py
as well?alex_dimov
11/24/2022, 11:22 AMalex_dimov
11/24/2022, 11:23 AMalex_dimov
11/24/2022, 11:23 AMReuben (Matatika)
11/24/2022, 11:25 AMdomain
is <http://sandbox-sa.hostedrmm.com|sandbox-sa.hostedrmm.com>
?alex_dimov
11/24/2022, 11:25 AMalex_dimov
11/24/2022, 11:25 AMReuben (Matatika)
11/24/2022, 11:35 AMContent-Type: application/json
header?alex_dimov
11/24/2022, 11:38 AMReuben (Matatika)
11/24/2022, 11:46 AMupdate_access_token
implementation into your authenticator class and make the changes you need - pretty sure that would just be changing this line to
token_response = <http://requests.post|requests.post>(self.auth_endpoint, data=auth_request_payload, headers={"Content-Type": "application/json"})
You could submit an issue to the SDK for a feature that would support configuration of request headers in update_access_token
. I don't know if this is as simple as just passing auth_headers
through...
@aaronsteers @edgar_ramirez_mondragonalex_dimov
11/24/2022, 12:11 PMIf an authenticator is also specified, the authenticator's headers will be combined with http_headers when making HTTP requests.
Reuben (Matatika)
11/24/2022, 12:22 PMauth_headers
will be combined with http_headers
in RESTStream
request sessions.
https://meltano.slack.com/archives/C01PKLU5D1R/p1669287517914089?thread_ts=1669286521.478099&cid=C01PKLU5D1Ralex_dimov
11/24/2022, 12:23 PMReuben (Matatika)
11/24/2022, 12:25 PMClientId
header now?alex_dimov
11/24/2022, 12:25 PMalex_dimov
11/24/2022, 12:26 PMAre you trying to pass theBut where can I put it?header now?ClientId
Reuben (Matatika)
11/24/2022, 12:26 PMbuild_prepared_request
is specific to RESTStream
, not an authenticator class.alex_dimov
11/24/2022, 12:27 PMalex_dimov
11/24/2022, 12:28 PMReuben (Matatika)
11/24/2022, 12:28 PMClientId
header as well, change to
token_response = <http://requests.post|requests.post>(self.auth_endpoint, data=auth_request_payload, headers={"Content-Type": "application/json", "ClientId", self.config['client_id']})
alex_dimov
11/24/2022, 12:29 PMalex_dimov
11/24/2022, 12:29 PMalex_dimov
11/24/2022, 1:04 PMalex_dimov
11/24/2022, 1:15 PMalex_dimov
11/24/2022, 1:17 PMalex_dimov
11/24/2022, 1:24 PMalex_dimov
11/24/2022, 1:25 PMReuben (Matatika)
11/24/2022, 1:25 PMalex_dimov
11/24/2022, 1:26 PMReuben (Matatika)
11/24/2022, 1:27 PMtoken_response = <http://requests.post|requests.post>(self.auth_endpoint, json=auth_request_payload, headers=headers)
Once you do that, you may not even need the Content-Type
header.alex_dimov
11/24/2022, 1:27 PMReuben (Matatika)
11/24/2022, 1:30 PMalex_dimov
11/24/2022, 1:31 PMReuben (Matatika)
11/24/2022, 1:32 PMalex_dimov
11/24/2022, 1:33 PMReuben (Matatika)
11/24/2022, 1:38 PMalex_dimov
11/24/2022, 1:39 PMReuben (Matatika)
11/24/2022, 1:41 PMalex_dimov
11/24/2022, 1:44 PMalex_dimov
11/24/2022, 1:48 PMalex_dimov
11/24/2022, 1:49 PMalex_dimov
11/24/2022, 1:52 PMalex_dimov
11/24/2022, 1:53 PMalex_dimov
11/24/2022, 2:24 PMReuben (Matatika)
11/24/2022, 2:34 PMupdate_access_token
should handle getting you a new token if one expires during runtime.alex_dimov
11/24/2022, 2:37 PMalex_dimov
11/24/2022, 5:45 PMReuben (Matatika)
11/25/2022, 1:08 AMself.access_token
is a string (i.e. not JSON). I don't know the API, but you maybe want something like
token_response = <http://requests.post|requests.post>(refresh_auth_endpoint, json={"AccessToken": self.access_token}, headers=self.def_headers)
https://gist.github.com/Volna13/80486df13a81f6add0927c3a4ca36a93#file-auth-py-L59
I don't think you actually need the explicit ClientId
header anymore, as <http://requests.post|requests.post>
should set it automatically given a value for the json
kwarg.
https://gist.github.com/Volna13/80486df13a81f6add0927c3a4ca36a93#file-auth-py-L79-L84
You don't need to check token validity here with self.is_token_valid()
as update_access_token
is only ever called when self.is_token_valid()
returns False
anyway. Think this whole bit can change to
token = self.refresh_exist_token() if self.access_token else self.get_token()
Reuben (Matatika)
11/25/2022, 1:11 AMrefresh_exist_token
and get_token
as they are very similar. Save that for another day though.alex_dimov
11/25/2022, 11:27 AMYou might run into problems here as I'm assumingNo, no, this is their stupid api again. This is how it looks like in POSTMAN(1 img) (in fact, I already checked this code and it works)is a string (i.e. not JSON). I don't know the API, but you maybe want something likeself.access_token
I don't think you actually need the explicitok, i will check, thanksheader anymore, asClientId
should set it automatically given a value for the<http://requests.post|requests.post>
kwarg.json
You don't need to check token validity here withGood catch. I will think Thanks for reviewasself.is_token_valid()
is only ever called whenupdate_access_token
returnsself.is_token_valid()
anyway. Think this whole bit can change toFalse