Magento 2 oauth 1获取请求令牌

时间:2017-07-26 14:53:22

标签: magento oauth magento2

无法在magento应用中获取请求令牌。签名始终无效。

这是我用来生成签名的代码。消费者密钥是我从localhost:8000(magento shop)请求到localhost:3000。

我尝试将网址都更改为localhost 8000和3000。

按照以下说明操作:Magento instructions

function getSignature($consumerKey)
{
    $params = array(
        'oauth_nonce' => uniqid(mt_rand(1, 1000)),
        'oauth_signature_method' => 'HMAC-SHA1',
        'oauth_timestamp' => time(),
        'oauth_version' => '1.0',
        'oauth_consumer_key' => $consumerKey,
    );

    ksort($params);
    $baseString = strtoupper('POST') . '&';
    $baseString .= rawurlencode('http://localhost:8000') . '&';
    $baseString .= rawurlencode(buildSignatureDataString($params));

    $signature = hash_hmac('SHA1', $baseString, getSigningKey(), true);

    return base64_encode($signature);
}

function getSigningKey()
{
    return rawurlencode('magento_private_key') . '&';
}

function buildSignatureDataString(array $signatureData)
{
    $signatureString = '';
    $delimiter = '';
    foreach ($signatureData as $key => $value) {
        $signatureString .= $delimiter . $key . '=' . $value;

        $delimiter = '&';
    }

    return $signatureString;
}

0 个答案:

没有答案