Skip to content
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

How to verify the event from webhook? #411

Open
letruonglamit opened this issue Jun 10, 2024 · 0 comments
Open

How to verify the event from webhook? #411

letruonglamit opened this issue Jun 10, 2024 · 0 comments

Comments

@letruonglamit
Copy link

I think we need to have something for verification the event like this

app.post('/webhook', (req, res) => {
    const event = req.body;

    // Verify the event (implement verification logic if necessary)
    if (!verifyMangopaySignature(req)) {
        return res.status(400).send({ status: 'error', message: 'Invalid signature' });
    }
    
 })
 
 function verifyMangopaySignature(req) {
    const signature = req.headers['x-request-signature'];
    const body = JSON.stringify(req.body);
    const secretKey = 'your_mangopay_secret_key'; // Replace with your actual secret key

    const hash = crypto
        .createHmac('sha256', secretKey)
        .update(body)
        .digest('hex');

    return signature === hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant