Skip to content

Instantly share code, notes, and snippets.

@gayanhewa
Created March 6, 2022 22:12
Show Gist options
  • Save gayanhewa/320bc86113bc178131fd87a05f786617 to your computer and use it in GitHub Desktop.
Save gayanhewa/320bc86113bc178131fd87a05f786617 to your computer and use it in GitHub Desktop.
Verify app proxy request if it came through Shopify or not
app.get("/app-proxy", async (req, res) => {
// Sorted list of query parameters
const q = {
path_prefix: req.query['path_prefix'],
shop: req.query['shop'],
timestamp: req.query['timestamp'],
};
const originalQuerystring = Object.keys(q).map(key => key + '=' + q[key]).join('');
const crypto = require('crypto')
function computeSignature(querystringFromClient, shopifyAppSecret) {
const computedSignature = crypto.createHmac('sha256', shopifyAppSecret)
.update(querystringFromClient, 'utf-8').digest('hex')
return computedSignature
}
const computedSignature = computeSignature(originalQuerystring, "API_SECRET_KEY")
console.log(originalQuerystring)
console.log(computedSignature, req.query);
if (computedSignature === req.query['signature']) {
res.setHeader('Content-Type', 'application/liquid');
res.send("Hello authenticated {{ customer.id }}");
} else {
res.send('Error');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment