/**
  * process Authorization Request
  *
  * @param Akita_OAuth2_Server_DataHandler $dataHandler
  */
 public function processAuthorizationRequest($dataHandler, $allowed_response_type = array('code', 'token', 'code token'))
 {
     $request = $dataHandler->getRequest();
     $response_type = isset($request->param['response_type']) ? $request->param['response_type'] : "";
     if (empty($response_type)) {
         throw new Akita_OAuth2_Server_Error('400', 'invalid_request', "'response_type' is required");
     }
     if (!in_array($response_type, $allowed_response_type)) {
         throw new Akita_OAuth2_Server_Error('400', 'unsupported_response_type');
     }
     // validate client_id
     $client_id = isset($request->param['client_id']) ? $request->param['client_id'] : "";
     if (empty($client_id)) {
         throw new Akita_OAuth2_Server_Error('400', 'invalid_request', "'client_id' is required");
     }
     if (!$dataHandler->validateClientById($client_id)) {
         throw new Akita_OAuth2_Server_Error('400', 'unauthorized_client');
     }
     // validate redirect_uri
     $redirect_uri = isset($request->param['redirect_uri']) ? $request->param['redirect_uri'] : "";
     if (empty($redirect_uri)) {
         throw new Akita_OAuth2_Server_Error('400', 'invalid_request', "'redirect_uri' is required");
     }
     if (!$dataHandler->validateRedirectUri($client_id, $redirect_uri)) {
         throw new Akita_OAuth2_Server_Error('400', 'invalid_request', "'redirect_uri' is invalid");
     }
     // validate scope
     $scope = isset($request->param['scope']) ? $request->param['scope'] : "";
     if (!$dataHandler->validateScope($client_id, $scope)) {
         throw new Akita_OAuth2_Server_Error('400', 'invalid_scope');
     }
 }
예제 #2
0
 /**
  * process API Request
  *
  * @param Akita_OAuth2_Server_DataHandler $dataHandler
  */
 public function processRequest($dataHandler)
 {
     $request = $dataHandler->getRequest();
     $param_access_token = $request->getAccessToken();
     if (empty($param_access_token)) {
         throw new Akita_OAuth2_Server_Error('400', 'invalid_request', "'access_token' is required");
     }
     $accessToken = $dataHandler->getAccessToken($param_access_token);
     if (is_null($accessToken)) {
         throw new Akita_OAuth2_Server_Error('401', 'invalid_token');
     }
     $authInfo = $dataHandler->getAuthInfoById($accessToken->authId);
     if (is_null($authInfo)) {
         throw new Akita_OAuth2_Server_Error('500', 'server_error');
     }
     return $authInfo;
 }