Created
March 13, 2020 17:09
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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