hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.18k stars 2.77k forks source link

Add support for request headers transform in Actions #10482

Open Li4m-B opened 3 months ago

Li4m-B commented 3 months ago

Is your proposal related to a problem?

I am trying to define an action that calls an external service. This service requires a specific Cookie to be present in the request headers for authentication, which the user should already have at the tame of calling the action.

However, I am not able to figure out a way to pass the cookie value to my webhook handler. I first tried using the Forward client headers to webhook option, but it doesn't seem to forward the Cookie header.

My idea was then to save the cookie token as part of my session variables (which we can do in our authentication service), and use a header transform to forward it to the webhook:

Screenshot 2024-07-29 at 15 28 29
Cookie: {{$session_variables["x-hasura-my-token']}}

It is then that I realized headers transform is not actually supported according to the documentation, resulting in the following error when calling the action:

{
  "errors": [
    {
      "message": "template cannot be resolved: $session_variables[\"x-hasura-my-token']",
      "extensions": {
        "path": "$",
        "code": "not-found"
      }
    }
  ]
}

Describe the solution you'd like

Ideally, it would be great if headers transform could be supported similarly to request body and url to make the above possible.

Describe alternatives you've considered

Alternately, allowing Cookie headers to be forwarded to the webhook could solve this specific use case.

rakeshkky commented 2 months ago

Hi @Li4m-B, the header value uses a templating system that only supports interpolation of environment variables. This design choice was established before the introduction of request transformation with Kriti templates. To support Kriti templates in header values, we need to introduce a new key, such as value_from_kriti.