Created
January 14, 2020 17:01
-
-
Save smashah/d0f0d40c0dd44b1fca01e2833b6c4168 to your computer and use it in GitHub Desktop.
Successfully validate a Starling Bank webhook signature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://stackoverflow.com/questions/56664705/nodejs-base-64-encoding-of-the-sha-512-digest/59738487#59738487 | |
const express = require("express"); | |
const crypto = require('crypto'); | |
const app = express(); | |
const bodyParser = require('body-parser'); | |
app.use(bodyParser.json({ | |
verify: (req, res, buf) => { | |
req.rawBody = buf | |
} | |
})); | |
app.post('/starling',async (request,response)=>{ | |
const secret = 'abcd-efgh-12f3-asd34-casd-whatever'; | |
let hash = crypto.createHash('sha512'); | |
hash.update(secret+request.rawBody); | |
const sigCheck = hash.digest('base64'); | |
const valid = sigCheck==request.headers['x-hook-signature']; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment