28 lines
1.0 KiB
PHP
28 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Security;
|
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
|
|
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
|
|
|
|
class AccessTokenDeniedHandler implements AccessDeniedHandlerInterface, AuthenticationFailureHandlerInterface
|
|
{
|
|
public function handle(Request $request, AccessDeniedException $accessDeniedException): ?Response
|
|
{
|
|
return new Response('AccessTokenDeniedHandler', 403);
|
|
}
|
|
|
|
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response
|
|
{
|
|
return new JsonResponse([
|
|
'result' => 'error',
|
|
'error' => $exception->getMessage()
|
|
]);
|
|
}
|
|
}
|