How to get bearer token from basic authentication?
In order to access the data we need, we have to send a POST request to https://pricemole.io/users/sign_in.json using basic authentication (username/password), then get the bearer token from the header and use it to send a GET request to https://pricemole.io/api/products.json.
How can we accomplish this without needing to manually get the bearer token each time?
0
Comments
Jared Fraley as a part of the release tomorrow, November 8th 2023, we natively can support this auth type via the universal HTTP connector. See below setup details:
Jared Fraley you would need to set the auth method on the connection to "token", then configure refresh token mechanism to use basic authentication. Here is an article on it and some example configs: https://docs.celigo.com/hc/en-us/articles/360045127771-Set-up-a-token-based-HTTP-connection#step-d.
Jared Fraley, I may take back what I said. Are you sure the bearer token is returned within the header of the response?
According to the documentation, yes.
Jared Fraley, unfortunately there isn't a way to currently handle that use case because we expect the token response to be in the body and we don't have a way to grab the headers and parse out the token from there.
There is a less clean way to do this with a myApi if you're open to that?
I am open to ideas. How would myApi work?
Jared Fraley it looks like I hit wall there as well. Virtual exports don't return the response headers, only response body, so it doesn't look like it's possible to use a myApi for this either. However, with the help of Anirudh Sundaram, he mentioned that we can get the the returned headers from import steps. So what I've done is make 2 flows.
Here is how to go about setting this up:
To do this, you'll need to create an api token from the left screen.
Base urI: https://api.integrator.io
Auth type: Token
Token: paste the token you generated here
Send token via: Header
Header Name: Authorization
Header scheme: Bearer
Under the advanced section, put this into the encrypted and unencrypted fields:
{"username":"actual value is in encrypted field, this field is here to remember the structure","password":"actual value is in encrypted field, this field is here to remember the structure"}
Modify the encrypted field section by putting your own credentials.
Save
Base urI: https://pricemole.io
Auth type: Token
Token: put a dummy value in for now
Send token via: Header
Header Name: Authorization
Header scheme: Bearer
Under the advanced section, put this into the encrypted and unencrypted fields:
{"username":"actual value is in encrypted field, this field is here to remember the structure","password":"actual value is in encrypted field, this field is here to remember the structure"}
Modify the encrypted field section by putting your own credentials.
Save
Please sign in to leave a comment.