1
0
mirror of synced 2024-11-24 22:06:06 +03:00
service-bundle/Security/AbstractClientAuthenticator.php

40 lines
1.3 KiB
PHP
Raw Normal View History

2021-02-05 14:47:54 +03:00
<?php
namespace RetailCrm\ServiceBundle\Security;
use Doctrine\Persistence\ObjectRepository;
2021-02-05 14:47:54 +03:00
use RetailCrm\ServiceBundle\Models\Error;
use RetailCrm\ServiceBundle\Response\ErrorJsonResponseFactory;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
2022-07-19 16:27:00 +03:00
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator;
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
2021-02-05 14:47:54 +03:00
2022-07-19 16:27:00 +03:00
abstract class AbstractClientAuthenticator extends AbstractAuthenticator
2021-02-05 14:47:54 +03:00
{
public const AUTH_FIELD = 'clientId';
2022-07-20 14:54:24 +03:00
public function __construct(private ErrorJsonResponseFactory $errorResponseFactory)
2021-02-05 14:47:54 +03:00
{
}
2022-07-19 16:27:00 +03:00
abstract public function supports(Request $request): ?bool;
2021-02-05 14:47:54 +03:00
2022-07-19 16:27:00 +03:00
abstract public function authenticate(Request $request): Passport;
2021-02-05 14:47:54 +03:00
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
{
$error = new Error();
$error->message = $exception->getMessageKey();
return $this->errorResponseFactory->create($error,Response::HTTP_FORBIDDEN);
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response
{
return null;
}
}