Firebase functions webhook validation

I am working in a nodejs firebase functions environment. Has anybody actually been able to get the webhook verified. I can send a request ok and validation works. Its just the incoming webhook. I have a feeling it might be to do with the body encoding and firebase functions doesnโ€™t let you get to the raw bodyโ€ฆ here is my code:
const validateRapydSignature = (req) => {
const signature = req.header(โ€˜signatureโ€™)
const urlPath = req.protocol + โ€˜://โ€™ + req.headers.host + req.originalUrl
const salt = req.header(โ€˜saltโ€™)
const timestamp = req.header(โ€˜timestampโ€™)
const bodyString = req.body
const secretKey = โ€˜โ€ฆโ€™
const accessKey = 'โ€ฆ

const dataToHash =
urlPath +
salt +
timestamp +
accessKey+
secretKey+
bodyString

let hash = crypto.createHmac(โ€˜sha256โ€™, secretKey)
hash.update(dataToHash)
const generatedSignature = Buffer.from(hash.digest(โ€˜hexโ€™)).toString(โ€˜base64โ€™)

return signature === generatedSignature
}

1 Like

Hey, @blakejp1 - are you still having this challenge? This doesnโ€™t appear to be an issue with the Rapyd API if I am reading correctly. Can you share your logs โ€“ also is this in the production or sandbox environment of Rapyd?

Hi Drew. thanks for the response. Yes I still have the challenge. I had to move on for now because I canโ€™t solve it but obviously I need to get it solved before going live. As an update I tried it with firebase functions req.rawBody instead of just req.body and I still get the issue. I am not saying its a rapyd issue, yet :} hence the question asking if anyone actually got it working with firebase functions version 2? I am wondering if they play with the rawBody or if the encoding is different or something. Like I say I can send to rapyd with a signature fine. not sure which logs you want but will get something over to you in the next couple of days.

1 Like

Sounds good. I will keep asking around if anyone else is having this challenge with Firebase and webhook validation.

Appreciated. And I forgot to add: yes its in the sandbox environment and associated keys

1 Like