27 lines
812 B
PHP
27 lines
812 B
PHP
<?php
|
|
|
|
namespace App\Security;
|
|
|
|
use App\Repository\AccessTokenRepository;
|
|
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
|
use Symfony\Component\Security\Http\AccessToken\AccessTokenHandlerInterface;
|
|
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
|
|
|
|
class AccessTokenHandler implements AccessTokenHandlerInterface
|
|
{
|
|
public function __construct(private AccessTokenRepository $accessTokenRepository)
|
|
{
|
|
}
|
|
|
|
public function getUserBadgeFrom(#[\SensitiveParameter] string $accessToken): UserBadge
|
|
{
|
|
$token = $this->accessTokenRepository->findOneBy(['token' => $accessToken]);
|
|
|
|
if (!$token) {
|
|
throw new BadCredentialsException();
|
|
}
|
|
|
|
return new UserBadge($token->getOwnedBy()->getUserIdentifier());
|
|
}
|
|
}
|