我已经使用此OAuth Library来连接Magento 2.1 REST API。获取Temporary Credentials的代码如下 -
if (isset($_GET['go'])) {
// First part of OAuth 1.0 authentication is retrieving temporary credentials.
// These identify you as a client to the server.
$temporaryCredentials = $server->getTemporaryCredentials();
// Store the credentials in the session.
$_SESSION['temporary_credentials'] = serialize($temporaryCredentials);
session_write_close();
// Second part of OAuth 1.0 authentication is to redirect the
// resource owner to the login screen on the server.
$server->authorize($temporaryCredentials);
// Step 1
} else {
// Display link to start process
echo '<a href="?go=go">Login</a>';
}
我获取临时证书的标题如下 -
[headers] => Array ( [Authorization] => OAuth oauth_consumer_key="l4y2cxabrklrch98r9s8wmuamgffra7v", oauth_nonce="uDiiz1wTGfFwCMbWXgv5JaB9EMq8u1PK", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1485165675", oauth_version="1.0", oauth_callback="http%3A%2F%2Flocalhost%3A24260%2Fsubamx%2FMPSMage%2FCode%2FAuth%2Fresources%2Fexamples%2Fmagento.php", oauth_signature="afMf5BuvUBlgoD1E9LKd9CjrVtU%3D" [Accept] => application/json )
我收到了这个错误 -
[message:protected] => Client error: `POST http://magento_store/oauth/token/request` resulted in a `401 Unauthorized` response: oauth_problem=Consumer+key+has+expired
[string:Exception:private] => [code:protected] => 401 [file:protected] => C:\xampp\htdocs\subamx\MPSMage\Code\Auth\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php [line:protected] => 111