Creating API Connector with Specific Authentication Method

Summary

The user is trying to create a connector using UI Builder for an API with a specific authentication method involving passing two HTTP headers. They are struggling to properly create the second header which requires a SHA-256 hash of a specific string. The issue arises from calling a macro within the authentication string.


Question

Hello there :octavia-wave:

I am trying to create a connector with the UI Builder for an API which uses a very specific authentication method, I need to pass two HTTP headers, as follows:
• One called Date with a value of the current date in UTC (Universal Time Code) format (i.e. Tue, 16 Jan 2024 13:26:59 GMT);
• One called Authentication with a value of the calculated authentication hash which is SHA-256 Hash in 64 character Hex format of the string “YourAPIToken:CurrentDateInUTCFormat:APIActionValue:YourAPISecret” (without quotes).
I’m thus trying to add these parameters in the request headers section of my streams. I’ve found for the first one that I can use the native macro "{{ now_utc() }}"

But now I really struggle to find a way to properly create the second header. I’ve made a lot of test iterations but here are the steps I followed to be the closest to what I’m trying to achieve:
• in the user inputs, I created an authentication_string with the following content my_api_token:{{ now_utc() }}:my_api_action:my_api_secret
• in the request headers, I created a header with the key Authentication
• for this header’s value, I’m calling the following value: {{ config['authentication_string'] | hash('sha256') }}
However, the problem is that calling the macro "{{ now_utc() }}" in this authentication string results in having the literal string "{{ now_utc() }}" and not the macro’s expected result (i.e. the current date in UTC format).

Is there a proper way to achieve such an authentication ?

Thank you very much!



This topic has been created from a Slack thread to give it more visibility.
It will be on Read-Only mode here. Click here if you want to access the original thread.

Join the conversation on Slack

["api-connector", "ui-builder", "authentication-method", "http-headers", "sha-256", "macro"]

Hello, Based on the information provided in the extracts, it seems that the Airbyte Connector Builder UI currently supports several authentication methods including Basic HTTP, Bearer Token, API Key, OAuth, and Session Token source. However, the specific authentication method you described, which involves creating a SHA-256 hash of a string that includes the current date in UTC format, may not be directly supported. The Connector Builder UI allows you to configure where to inject the API key (header, request param, or request body), as well as under which field name source. However, it does not seem to support the dynamic generation of a hash based on the current date and other parameters. In the case of more complex or custom authentication methods, the documentation suggests using the low-code CDK or Python CDK source. These tools provide more flexibility and control over the authentication process. For your specific case, you might need to use the Python CDK to create a custom connector that can handle your API’s unique authentication requirements. The Python CDK allows you to write custom Python code to handle the authentication process, which could include generating a SHA-256 hash of a string that includes the current date in UTC format. I hope this helps! If you have further questions, feel free to ask.

If it might help anyone trying to dynamically hash date in a HHTP header, here is how i’ve managed to do it using jinja syntax in the value case of my header:
{{ ("my_api_token:" ~ now_utc().strftime("%a, %d %b %Y +0000") ~ ":my_api_action:my_api_secret") | hash('sha256') }}