Exemple #1
0
 public function handle(\Symfony\Component\HttpFoundation\Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     if (!$request->headers->has('Authorization')) {
         $exception = new UnauthorizedException("No token provided.");
         $response = $exception->getJsonResponse();
         return $response;
     }
     if ($request->headers->get('Authorization') === null) {
         $exception = new UnauthorizedException("No authorization header sent.");
         $response = $exception->getJsonResponse();
         return $response;
     }
     $token = $this->auth->attempt(str_replace('Bearer ', '', $request->headers->get('Authorization')));
     if (get_class($token) !== 'stdClass') {
         $exception = new UnauthorizedException($token->getMessage());
         $response = $exception->getJsonResponse();
         return $response;
     }
 }
Exemple #2
0
 public function handleUnauthorized()
 {
     $message = 'You are not authorized!';
     if ($this->getStrategy() instanceof RestfulStrategy) {
         $exception = new UnauthorizedException($message);
         return $exception->getJsonResponse();
     }
     return new Response($this->container->get('view')->render('Admin::exception/unauthorized', ['message' => $message]), 403);
 }