Skip to content

Instantly share code, notes, and snippets.

@missoxd
Created March 13, 2020 17:09
Show Gist options
  • Save missoxd/b8defcf160996a42fa7c28a73bc6cb97 to your computer and use it in GitHub Desktop.
Save missoxd/b8defcf160996a42fa7c28a73bc6cb97 to your computer and use it in GitHub Desktop.
<?php
/**
* Quando precisamos pegar o request_token e o token_verifier.
*
* 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> <admin-path> <callback-url> <consumer-key> <consumer-secret>
Exemplo:
php -f magento1-get-token-step-1.php "https://magento.host/" "admin" "https://callback.host/" "my-consumer-key" "my-consumer-secret"
EOD;
die($msg);
}
if (!isset($argc) || $argc !== 6) {
usage();
}
$url = rtrim($argv[1], '/');
$admin = $argv[2];
$callback = $argv[3];
$consumerKey = $argv[4];
$consumerSecret = $argv[5];
try {
$oauth = new \OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$token = $oauth->getRequestToken("$url/oauth/initiate?oauth_callback=".urlencode($callback));
die("Secret: {$token['oauth_token_secret']}\nVisit: {$url}/{$admin}/oauth_authorize?oauth_token={$token['oauth_token']}\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