Background: An overview of Basic authentication can be found here. It is a simple HTTP authentication method where you provide your encoded username and password in the request. Only standard HTTP headers are required, no cookies or login pages needed.
Objective and Scenario:
You have an API that you need to connect to in your workflow and Tray does not have any native connectors for it. Furthermore, you read in your service’s API docs that it uses Basic Authentication.
So, you will need to create a custom service in Tray to handle the Authentication and then use the HTTP client to make the requests.
Encoding the credentials:
Per the standard, you will need to Base64 encode your credentials, given in the format username:password (email or user can be used interchangeably).
You could make use of Tray’s own text helper to encode the credentials for you, however, it may be a security risk, as the credentials would be exposed in the logs
Instead you can use your own encoder tool, such as this free one online. As an example, the resulting credentials may look similar to: ZmFrZUBnbWFpbC5jb206cGFzczEyMzQ=
Add your Service:
In your Tray dashboard, on the left hand side, you can navigate to Services, then “New Service”. When you are done configuring, click on “Add Service”.
The service will need to have a field to enter your encoded credentials. In the example below we’ve added the Title "API Key" with a field of Type "Password”. You can use any name you’d like, such as “credentials”
Create the Authentication:
After adding this Service, you can then go back to your Tray dashboard, and go to Authentications -> Create New Authentication. Here, you can name your Auth and choose the service you just created. Then enter your "API Key", which would be the encoded credentials.
Setup the HTTP Client and Test:
Finally, in your workflow, after adding the HTTP client and selecting the Authentication you just created, you can configure the headers to be as below, where the Authorization "Value" is: Basic {$.auth.api_key}
.
Then, you can test a request to a specific endpoint/URL.
Comments
0 comments
Please sign in to leave a comment.