Bom dia, estou desenvolvendo um projeto pessoal com symfony porém sem doctrine, desenvolvi o sistema de login e ele ja retorna o token criptografado com JWT::encode, porém quando coloco o arquivo de autenticação no security, aparece esse erro:
Unrecognized option "entity" under "security.providers.app_user_provider". Available options are "chain", "id", "ldap", "memory"
Arquivo security.yaml
security:
encoders:
App\Entity\User:
algorithm: argon2i
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
logout: ~
guard:
authenticators:
~ App\Security\JwtAutenticador
<?php
Arquivo em php
namespace App\Security;
use App\Repository\EntityManager;
use App\Infra\EntityManagerCreator;
use Firebase\JWT\JWT;
use Symfony\Component\HttpFoundation\JsonResponse;
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;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
class JwtAutenticador extends AbstractGuardAuthenticator
{
public function __construct()
{
$entityManager = (new EntityManagerCreator())->getEntityManager();
$this->repository = $entityManager->getRepository(User::class);
}
public function start(Request $request, AuthenticationException $authException = null)
{
// TODO: Implement start() method.
}
public function supports(Request $request)
{
return $request->getPathInfo() !== '/api/login-supermarket';
}
public function getCredentials(Request $request)
{
$token = str_replace(
'Bearer',
'',
$request->headers->get('Authorization')
);
try {
return JWT::decode($token, 'key', ['HS256']);
} catch (\Exception $e) {
return false;
}
}
public function getUser($credentials, UserProviderInterface $userProvider)
{
if (!is_object($credentials) || !property_exists($credentials, 'email')) {
return null;
}
$email = $credentials->email;
return $this->repository->findOneBy('supermarket', $email);
}
public function checkCredentials($credentials, UserInterface $user)
{
return is_object($credentials) && property_exists($credentials, 'email');
}
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
return new JsonResponse([
'erro' => 'Falha na autenticação'
], Response::HTTP_UNAUTHORIZED);
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
return null;
}
public function supportsRememberMe()
{
return false;
}
}