【问题标题】:Detect if a request comes from within the Shopify Admin Panel检测请求是否来自 Shopify 管理面板
【发布时间】:2016-06-23 21:16:28
【问题描述】:

我正在使用嵌入式应用程序 SDK(用于构建 Shopify 应用程序),它允许我在管理面板中显示网页。假设 Shopify 应用程序的 URL 为 /shopifyApp 。每当用户点击上述应用程序时,他都会被重定向到“/shopifyApp”。 获取请求看起来像 /shopifyApp?hmac=b20934d6b66cxxx&protocol=https%3A%2F%2F&shop=dev-store-61.myshopify.com&timestamp=1466715935

我正在尝试验证 hmac 是否有效。我正在使用下面的代码进行验证,但不幸的是它不起作用。

var map = JSON.parse(JSON.stringify(req.query));
    delete map['hmac'];
    var message = querystring.stringify(map);
    var generated_hash = require('crypto').createHmac('sha256', "myAppSecret").update(message).digest('hex');
    if (generated_hash === req.query.hmac) {
       //show Authenticated page
    } else {
        //Show unauthenticated page
    }

由于某种原因,生成的 has 永远不会等于 hmac。有人可以告诉我我做错了什么吗?

【问题讨论】:

    标签: node.js oauth passport.js shopify hmac


    【解决方案1】:

    你需要删除hmac和签名

    function verifyRequest(req, res, next) {
    var map = JSON.parse(JSON.stringify(req.query));
    delete map['signature'];
    delete map['hmac'];
    
    var message = querystring.stringify(map);
    var generated_hash = crypto.createHmac('sha256', config.oauth.client_secret).update(message).digest('hex');
    if (generated_hash === req.query.hmac) {
        next();
    } else {
        return res.json(400);
    }
    

    }

    【讨论】:

    • 我没有收到签名
    猜你喜欢
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-14
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    相关资源
    最近更新 更多