public function test_processAuthorizationRequest_invalid_scope() { $server = array(); $params = array('response_type' => 'code token', 'client_id' => 'valid_client_id', 'redirect_uri' => 'http://valid_redirect_uri/'); $request = new Akita_OAuth2_Server_Request('authorization', $server, $params); $dataHandler = new DataHandler_AuthorizationHandler_Test($request, null, null); $authHandler = new Akita_OAuth2_Server_AuthorizationHandler(); try { $authHandler->processAuthorizationRequest($dataHandler); } catch (Akita_OAuth2_Server_Error $error) { $this->assertEquals('400', $error->getOAuth2Code(), $error->getMessage()); $this->assertEquals('invalid_scope', $error->getOAuth2Error(), $error->getMessage()); $this->assertEmpty($error->getOAuth2ErrorDescription(), $error->getMessage()); } }
<?php session_name('AkitaOAuth2ServerSample'); session_start(); require_once './lib/DataHandler.php'; // process request $headers = apache_request_headers(); $request = new Akita_OAuth2_Server_Request('authorization', $_SERVER, $_GET, $headers); $dataHandler = new Akita_OAuth2_Server_Sample_DataHandler($request); $authHandler = new Akita_OAuth2_Server_AuthorizationHandler(); try { $authHandler->processAuthorizationRequest($dataHandler); } catch (Akita_OAuth2_Server_Error $error) { // error handling include './tmpl/error.html'; exit; } // login $email = $_SESSION['email']; $redirectUri = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $_SESSION['redirect_uri'] = $redirectUri; if (empty($email)) { header('location: ./Login.php'); exit; } // store request $_SESSION['server_request'] = serialize($request); $_SESSION['server_ts'] = time(); $_SESSION['server_key'] = mt_rand(); $request_hash = hash_hmac('sha256', $_SESSION['server_request'] . $_SESSION['server_ts'], $_SESSION['server_key']); $denied_url = str_replace('Authorization.php', 'Finish.php', 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']) . '?request_hash=' . urlencode($request_hash) . '&deny=1';