示例#1
0
 /**
  * Returns HTTP response explaining the error that caused the exception.
  *
  * @return Response
  */
 public function returnResponse()
 {
     $response = new Response();
     $response->setStatusCode(409, 'Fb user is not valid');
     $response->setJsonContent(['status' => 'ERROR', 'message' => $this->resource->getMessages()]);
     return $response;
 }
 /**
  * Returns HTTP response explaining the error that caused the exception.
  *
  * @return Response
  */
 public function returnResponse()
 {
     $response = new Response();
     $response->setStatusCode(409, 'Error during FB callback');
     $response->setJsonContent(['status' => 'ERROR', 'message' => $this->message]);
     return $response;
 }
 /**
  * Returns HTTP response explaining the error that caused the exception.
  *
  * @return Response
  */
 public function returnResponse()
 {
     $response = new Response();
     $response->setStatusCode(404, 'Resource Not Found');
     $response->setJsonContent(['status' => 'ERROR', 'message' => $this->message]);
     return $response;
 }
 /**
  *  @SWG\Post(
  *      path="/oauth/token",
  *      tags={"oauth"},
  *      summary="Request for a valid access token",
  *      description="Given client_id and client_secret a valid access token is issued.",
  *      operationId="getToken",
  *      consumes={"application/x-www-form-urlencoded"},
  *      @SWG\Parameter(
  *          in="formData",
  *          name="grant_type",
  *          description="Type of grant wanted.",
  *          required=true,
  *          type="string",
  *          enum={"client_credentials"},
  *      ),
  *      @SWG\Parameter(
  *          in="formData",
  *          name="client_id",
  *          description="A valid client_id.",
  *          required=true,
  *          type="string",
  *      ),
  *      @SWG\Parameter(
  *          in="formData",
  *          name="client_secret",
  *          description="A valid client_secret.",
  *          required=true,
  *          type="string",
  *      ),
  *      @SWG\Parameter(
  *          in="formData",
  *          name="scope",
  *          description="List of scopes separated by comma.",
  *          required=false,
  *          type="string",
  *      ),
  *      @SWG\Parameter(
  *          in="formData",
  *          name="state",
  *          description="String parameter to check if there is no man in the middle.",
  *          required=false,
  *          type="string",
  *      ),
  *      @SWG\Response(
  *          response=200,
  *          description="Successfully created",
  *          @SWG\Schema(),
  *          examples={
  *              "application/json": {
  *                  "access_token": "a63097c58497b42bf2793e1f7851fe10ae7cff18",
  *                  "expires_in": 3600,
  *                  "token_type": "Bearer",
  *                  "scope": null
  *              }
  *          },
  *      ),
  *      @SWG\Response(
  *          response=400,
  *          description="Bad request. Some parameter is missing.",
  *      ),
  *  )
  */
 public function getToken()
 {
     // TODO: return same access token if not expired
     $request = Request::createFromGlobals();
     // Handle a request for an OAuth2.0 Access Token and send the response to the client
     return Response::responseFromOAuth($this->oauth->handleTokenRequest($request));
 }
示例#5
0
 public function createRouter()
 {
     $path = $this->parseUrl($this->url);
     if (empty($path)) {
         $this->httpResponse->redirect('homepage');
     }
     $controllerClass = 'App\\Controllers\\' . $this->kebabCaseToCamelCase(array_shift($path)) . 'Controller';
     if (!class_exists($controllerClass)) {
         if (!class_exists('App\\Controllers\\ErrorController')) {
             throw new \Exception('App\\Controllers\\ErrorController not found.');
         }
         $this->httpResponse->redirect('error');
     }
     /** @var App\Controllers\BaseController $controller */
     $controller = new $controllerClass();
     $controller->process($path);
     $controller->render();
 }
 public function call(Micro $application)
 {
     $oauth = $application['oauth'];
     $url = strtok($_SERVER["REQUEST_URI"], '?');
     if (!in_array($url, self::$excepted_routes)) {
         // Handle a request to a resource and authenticate the access token
         if (!$oauth->verifyResourceRequest(Request::createFromGlobals())) {
             Response::responseFromOAuth($oauth->getResponse())->send();
             throw new UnauthorizedRequest();
         }
     }
     return true;
 }
 /**
  * Check if the resource is saved or not and returns a response depending on this.
  * @param $resource
  * @return Response
  */
 protected function response($resource)
 {
     // Create a response
     $response = new Response();
     // Request method
     $method = $this->request->getMethod();
     if ($method === "POST" || $method === "PUT") {
         if ($resource->save() == true) {
             // Change the HTTP status
             if ($method === "POST") {
                 $response->setStatusCode(201, "Created");
             } else {
                 $response->setStatusCode(200, "Updated");
             }
             $response->setJsonContent(array('status' => 'OK', 'data' => $resource));
         } else {
             $response = new Response();
             // Change the HTTP status
             $response->setStatusCode(409, "Conflict");
             // Send errors to the client
             $errors = array();
             foreach ($resource->getMessages() as $message) {
                 $key = $message->getField();
                 if (empty($key)) {
                     $errors[] = $message->getMessage();
                 } else {
                     if (!isset($errors[$key])) {
                         $errors[$key] = array();
                     }
                     $errors[$key][] = $message->getMessage();
                 }
             }
             $response->setJsonContent(array('status' => 'ERROR', 'messages' => $errors));
         }
     } else {
         if ($resource->delete() == true) {
             $response->setStatusCode(200, "Deleted");
             $response->setJsonContent(array('status' => 'OK'));
         } else {
             // Change the HTTP status
             $response->setStatusCode(409, "Conflict");
             $response->setJsonContent(array('status' => 'ERROR', 'messages' => 'Internal error while deleting'));
         }
     }
     return $response;
 }
示例#8
0
 /**
  * Gestion en appel statique
  *
  * @return Response
  */
 public static function __callStatic($method, $arguments)
 {
     $object = Response::getInstance();
     return call_user_func_array([$object, $method], $arguments);
 }