public static function execute() { echo __CLASS__ . PHP_EOL; echo 'Запрос токена по коду авторизации: '; $form = array('grant_type' => 'authorization_code', 'code' => tmsContext::getInstance()->getCode()); tmsContext::getInstance()->unsetCode(); //curl -u testclient:testpass http://localhost/token.php -d 'grant_type=authorization_code&code=YOUR_CODE' $address = tmsApiConfig::getInstance()->getActionAddress('oauth_get_token'); $result = tmsApiClient::POST('" -u testclient:testpass "' . $address, $form); $result = json_decode($result, true); if ($result && isset($result['access_token'])) { tmsContext::getInstance()->setOauth($result); echo 'Токен получен: '; } }
public static function execute() { echo __CLASS__ . PHP_EOL; echo 'Запрос кода авторизации: '; $get_params = array('response_type' => 'code', 'client_id' => 'testclient', 'state' => 'xyz'); $form = array('authorized' => 'yes'); $address = tmsApiConfig::getInstance()->getActionAddress('oauth_get_code'); $result = tmsApiClient::POST($address, $form, $get_params); echo $result . PHP_EOL; $result = json_decode($result, true); // print_r($result); if ($result && isset($result['code'])) { tmsContext::getInstance()->setCode($result['code']); return true; } return false; }
<?php /** * Created by PhpStorm. * User: morozov * Date: 07.09.2015 * Time: 13:09 */ define('PATH_LIB', __DIR__ . '/lib/'); define('PATH_CACHE', __DIR__ . '/cache/'); require_once PATH_LIB . 'bootstrap.php'; $context = tmsContext::getInstance(); $cl = tms_ConsoleFlow::getInstance(); $cl->row_print('Select action:'); api_getOauthCode::execute(); api_getOauthTokenByCode::execute();