Ejemplo n.º 1
0
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
use RestService\Utils\Config;
use RestService\Utils\Logger;
use RestService\Http\HttpRequest;
use RestService\Http\IncomingHttpRequest;
use OAuth\Authorize;
use RestService\Http\HttpResponse;
$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));
    $a = new Authorize($config, $logger);
    $request = HttpRequest::fromIncomingHttpRequest(new IncomingHttpRequest());
    $response = $a->handleRequest($request);
} catch (Exception $e) {
    // internal server error, inform resource owner through browser
    $response = new HttpResponse(500);
    $loader = new \Twig_Loader_Filesystem(dirname(__DIR__) . DIRECTORY_SEPARATOR . "views");
    $twig = new \Twig_Environment($loader);
    $output = $twig->render("error.twig", array("statusCode" => $response->getStatusCode(), "statusReason" => $response->getStatusReason(), "errorMessage" => $e->getMessage()));
    $response->setContent($output);
    if (NULL !== $logger) {
        $logger->logFatal($e->getMessage() . PHP_EOL . $request . PHP_EOL . $response);
    }
}
if (NULL !== $logger) {
    $logger->logDebug($request);
 public function testWrongClientType()
 {
     $h = new HttpRequest("https://auth.example.org?client_id=testclient&scope=read&response_type=code", "GET");
     $o = new Authorize($this->_config);
     $response = $o->handleRequest($h);
     $this->assertEquals(302, $response->getStatusCode());
     $this->assertEquals("http://localhost/php-oauth/unit/test.html#error=unsupported_response_type&error_description=response_type+not+supported+by+client+profile", $response->getHeader("Location"));
 }