首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shopify验证失败

Shopify验证失败
EN

Stack Overflow用户
提问于 2020-04-15 22:15:44
回答 1查看 79关注 0票数 0

我正在尝试在Shopify中创建一个公共应用程序。我可以设置我们的应用程序所需的范围。在安装过程中,它要求shopify验证。我已经参考了这个文档https://shopify.dev/tutorials/authenticate-with-oauth#verification。我将消息作为code=%code-from-shopify%&shop=%shop.myshopify.com%&state=%state-from-shopify%×tamp=%timestamp-from-shopify%传递,将secret作为Shopify应用程序的密钥,但它永远不会与url中的hmac作为参数匹配。

我在3年前创建了一个应用程序,正如我上面提到的,它工作得很好,但是当我在9天前创建了一个应用程序时,它不能工作,这个新应用程序的密钥是从shpss_开始的

我该如何解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2021-03-25 18:03:17

  • 首先请检查您的SHOPIFY_KEY和SHOPIFY_SECRET是否正确,以及您是否在代码中使用了相同的内容。
  • 一旦您从购物重定向到给定的呼叫backUrl,您将从请求中获得hmac和代码。

下面是从hmac获取访问令牌的代码

代码语言:javascript
复制
foreach ($_REQUEST as $key => $value) {
    if ($key !== "hmac" && $key != "signature") {
        $hashArray[] = $key . "=" . $value;
    }
}
$hashString   = implode($hashArray, "&");
$hashedString = hash_hmac("sha256", $hashString, 'YOUR_SHOPIFY_SECRET');

/* compare resulting hashed string with hmac parameter */
if ($_REQUEST['hmac'] !== $hashedString) {
    return 403;
}

$shopUrl  = "https://" . $_REQUEST["shop"] . "/admin/oauth/access_token.json";
$postData = http_build_query(
    array(
        "client_id"     => 'YOUR_SHOPIFY_KEY',
        "client_secret" => 'YOUR_SHOPIFY_SECRET',
        "code"          => $_REQUEST["code"],
    )
);

/* Call using curl post you will get Access token in JSON */
$result = shop_auth_curl_request_call($shopUrl, $postData);

$tokenResponse = json_decode($result, true);

$tokenResponse['access_token'] // In JSON you will get access token
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61231021

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档