public function testRefreshTokenNoSubScope() { $h = new HttpRequest("https://auth.example.org/token", "POST"); $h->setBasicAuthUser("testcodeclient"); $h->setBasicAuthPass("abcdef"); $h->setPostParameters(array("refresh_token" => "r3fr3sh", "scope" => "we want no sub scope", "grant_type" => "refresh_token")); $t = new Token($this->_config, NULL); $response = $t->handleRequest($h); $this->assertEquals(200, $response->getStatusCode()); $this->assertRegexp('|^{"access_token":"[a-zA-Z0-9]+","expires_in":5,"scope":"read write foo","token_type":"bearer"}$|', $response->getContent()); }
use RestService\Http\HttpResponse; use RestService\Utils\Config; use RestService\Http\IncomingHttpRequest; use RestService\Http\HttpRequest; use OAuth\Token; use RestService\Utils\Logger; use RestService\Utils\Json; $logger = NULL; $request = NULL; $response = NULL; try { $config = new Config(dirname(__DIR__) . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "oauth.ini"); $logger = new Logger($config->getSectionValue('Log', 'logLevel'), $config->getValue('serviceName'), $config->getSectionValue('Log', 'logFile'), $config->getSectionValue('Log', 'logMail', FALSE)); $t = new Token($config, $logger); $request = HttpRequest::fromIncomingHttpRequest(new IncomingHttpRequest()); $response = $t->handleRequest($request); } catch (Exception $e) { $response = new HttpResponse(500, "application/json"); $response->setContent(Json::enc(array("error" => $e->getMessage()))); if (NULL !== $logger) { $logger->logFatal($e->getMessage() . PHP_EOL . $request . PHP_EOL . $response); } } if (NULL !== $logger) { $logger->logDebug($request); } if (NULL !== $logger) { $logger->logDebug($response); } if (NULL !== $response) { $response->sendResponse();