Skip to content

Commit

Permalink
feat(indiekit): support x-webhook-signature header
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 3, 2023
1 parent cf1a912 commit a61ae7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/indiekit/lib/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export const findBearerToken = (request) => {
return bearerToken;
}

// https://docs.netlify.com/site-deploys/notifications/#payload-signature
if (request.headers?.["x-webhook-signature"]) {
const bearerToken = request.headers["x-webhook-signature"];
return bearerToken;
}

if (request.body?.access_token) {
const bearerToken = request.body.access_token;
delete request.body.access_token;
Expand Down
9 changes: 9 additions & 0 deletions packages/indiekit/tests/unit/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ test("Returns bearer token from `headers.authorization`", (t) => {
t.is(result, "JWT");
});

test("Returns bearer token from `headers.x-webhook-signature`", (t) => {
const request = {
headers: { "x-webhook-signature": t.context.bearerToken },
};
const result = findBearerToken(request);

t.is(result, "JWT");
});

test("Returns bearer token from `body.access_token`", (t) => {
const request = { body: { access_token: t.context.bearerToken } };
const result = findBearerToken(request);
Expand Down

0 comments on commit a61ae7f

Please sign in to comment.