MyComments/src/Security/AccessTokenDeniedHandler.php
Skylar 7c45f64a73 - Added support for authenticating via access tokens
- update symfony to 6.4.*
- some other minor stuff
2024-02-12 23:39:11 -07:00

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()
]);
}
}