43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Security;
|
|
|
|
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
|
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\Http\Authenticator\AbstractAuthenticator;
|
|
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
|
|
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
|
|
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
|
|
|
|
class Authenticator extends AbstractAuthenticator
|
|
{
|
|
public function __construct(private ClientRegistry $clientRegistry)
|
|
{
|
|
}
|
|
|
|
public function supports(Request $request): ?bool
|
|
{
|
|
return $request->attributes->get('_route') === 'auth_callback';
|
|
}
|
|
|
|
public function authenticate(Request $request): Passport
|
|
{
|
|
dd($this->clientRegistry->getClient('auth')->getAccessToken());
|
|
|
|
return new SelfValidatingPassport(new UserBadge(''));
|
|
}
|
|
|
|
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
|
|
{
|
|
dd($request );
|
|
}
|
|
} |