Skip to content

Instantly share code, notes, and snippets.

@missoxd
Created March 13, 2020 17:09
Show Gist options
  • Save missoxd/79b19939bca30c1dc7ac1fd3e533a5d4 to your computer and use it in GitHub Desktop.
Save missoxd/79b19939bca30c1dc7ac1fd3e533a5d4 to your computer and use it in GitHub Desktop.
<?php
/**
* Quando precisamos pegar o access_token e token_secret.
*
* Precisamos ter a OAuth lib instalada no PHP, caso ela não esteja presente, no Ubuntu podemos instalar com:
* $ sudo apt install php-oauth
*/
function usage()
{
$msg = <<<EOD
Usage:
php -f magento1-get-token-step-1.php <base-url> <consumer-key> <consumer-secret> <token> <token-secret> <token-verifier>
Exemplo:
php -f magento1-get-token-step-1.php "https://magento.host/" "my-consumer-key" "my-consumer-secret" "my-token" "my-token-secret" "my-token-verifier"
EOD;
die($msg);
}
if (!isset($argc) || $argc !== 7) {
usage();
}
$url = rtrim($argv[1], '/');
$consumerKey = $argv[2];
$consumerSecret = $argv[3];
$token = $argv[4];
$tokenSecret = $argv[5];
$tokenVerifier = $argv[6];
try {
$oauth = new \OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->setToken($token, $tokenSecret);
$accessToken = $oauth->getAccessToken("$url/oauth/token", null, $tokenVerifier);
die("Token: {$accessToken['oauth_token']}\nToken Secret: {$accessToken['oauth_token_secret']}\n");
} catch (\OAuthException $e) {
print_r($e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment