Setting Authorization Header in Webhooks

Hi, I want to set Authorization header in my webhook. How can we do that?

2 Likes

Hi @lghai, I’m not sure about this, so I’ll pass it to the @team-tech-support to see if they can help you with this. Someone there will get back to you as soon as they pick this up from their queue.

What was the outcome of this?

@juj @lghai This is still in the @team-tech-support queue, so it hasn’t been forgotten or lost. I just sent a message reminding the dev team about this, so hopefully they will address it soon and get back to you.

1 Like

Okey :+1:

Would love to know if there are any plans to allow us to add our own headers and payload to the webhook request. Right now I can not connect the Prismic webhook directly to Github Actions. Instead I have to use a lambda function in-between that can put the "secret" into an authentication header and add the required payload.

1 Like

Hello! Is there any update on that matter? I'm trying to query a jenkins server with a hook and there's no way to pass the Basic Auth unless I missed something. Thanks!

@sebastien1 I'll follow up with the dev team to see if someone there can respond.

Hi, just wondering if there's been any update here as I also would need this feature for integration with Digital Ocean's app platform. Currently, it wants headers to have an auth header with bearer-token. Does Prismic support that?

1 Like

Oh crap I really need this also to support Github Actions, I never imagined that the webhooks feature wouldn't support Github.

Yes please get this moving asap!!

Sounds like you worked out a bit of a workaround. Would you mind sharing your code?

Hi Everyone,

So the team has prioritised creating a fix for this for next week. They will contact you here once they have an update or need more infromation.

Thanks.

2 Likes

Sure :slight_smile:

I have created a lambda function called forwardPrismicWebhook (to Github Actions).

I have set Prismic up to call the lambda's url with a query parameter for the prismic repository, so that I can use the same lambda for multiple Prismic repos. E:g. forward-prismic-webhook-url?repository=myrepo.

In my lambda I do something like this:

const bodyFromPrismic = JSON.parse(event.body);
const data = {
   event_type: "prismic-publish",
};

const githubActionsUrl = getGithubActionsUrl(
   event.queryStringParameters.repository
);

const config = createConfig(bodyFromPrismic.secret, data);

try {
  const resp = await axios.post(githubActionsUrl, data, config);
  console.log("Response from Github Actions: ", resp);
  return successResponse(
    event,
    "Github Actions webhook called successfully!"
  );
} catch (err) {
  console.error(err);
  return errorResponse(event, "Failed to call Github Actions webhook!");
}

The getGithubActionsUrl method is just a switch-case that returns the url to the corresponding Github Actions for one of my Prismic repositories.

The createConfig creates the headers I needed to call Github Actions with

const createConfig = (authToken: string, data: any) => {
  return {
    headers: {
      "Content-Type": "application/json",
      "Content-Length": data.length,
      Accept: "application/vnd.github.everest-preview+json",
      Authorization: "Bearer " + authToken,
      "User-Agent": "Prismic",
    },
  };
};
2 Likes

I find out an OK work around for this in Next.js. Simply add an endpoint in the /pages/api that can receive the webhook from prismic and send its own hook to Digital Ocean with the necessary auth header. Prismic has a field for secret, so you can enter the token there or get it from an env var.

Thanks so much @Phil, that is greatly appreciated :smiley:

While they are looking at Webhooks can they also add support for setting Headers and a Body, as raised by @ gctravelapp here.

Hey,

I've let the team know about this. Once I get an update I'll let you know here.

1 Like

Checking in on this one.

Supporting webhooks that allow us to set an Authorization header and add a response body is really critical.

Specifically the primary use case for me is being able to support Github Actions.

Thanks

1 Like

Hey,

This is currently still being worked on by the team. I agree this is important for many users such as yourself and the team is working hard to get this improvement out as soon as possible, but I would imagine it will be a few weeks before this is complete.

Your use case of github actions is one that we are taking in to consideration in our work.

Thanks.

1 Like

Thanks for working on this! If the team is looking for another concrete use case, my team is hoping to be able to trigger CircleCI workflows for our site build by posting payloads along the lines of
{"branch":"branch","parameters":{"website":true}}
For our use case, fixed payloads would be totally ok!

Thanks!

1 Like

Thank you for the extra information. I've passed this to the team.

The team is currently working on this. We'll update you here once it's shipped.