-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify HMAC fails #11
Comments
I was using the private key to validate the IPN, I switched to IPNSecret but now, bellow error is raised.
|
@OrahKokos import express from "express";
import crypto from 'crypto';
app.use(express.json());
app.use(express.urlencoded({ extended: true,
verify: (req: express.Request, res, buf, encoding) => {
req.rawBody = buf.toString();
}}
));
const checkHmac = (theirHmac: string, IPNSecret: string, rawBody: string) => {
const ourHmac = crypto.createHmac('sha512', IPNSecret).update(rawBody).digest('hex');
return ourHmac == theirHmac;
}
app.post('/verify', async (req, res) => {
const IPNSecret = process.env['IPNSecret'];
const hmac = req.params['hmac'];
console.log("is hmac valid: ", checkHmac(hmac, IPNSecret, req.rawBody));
res.send();
});
app.listen(3000, () => {
logger.info(`Example app listening at http://localhost:3000`)
});
Output
_______________________________________
is hmac valid: true For future visitors: I didn't run the above code, Probably It will need some tweaks, they are simplified for demonstration, By the way, I'm new to typescript and the whole JS world. @OrahKokos |
Greetings @Dawoodkhorsandi Its at a point where it needs to be deployed to some env and tested. |
Hi there,
I'm trying to verify the IPN using hmac, this is my sample code.
Unfortunately verify always returns false.
The text was updated successfully, but these errors were encountered: