feat: password grant

This commit is contained in:
Björn Fromme
2026-07-10 09:02:33 +02:00
parent de37186706
commit f5f84ad98e
3 changed files with 49 additions and 2 deletions
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\EventListener;
use App\Security\Crypt;
use League\Bundle\OAuth2ServerBundle\Event\UserResolveEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
#[AsEventListener(event: 'league.oauth2_server.event.user_resolve', method: 'onUserResolve')]
final class UserResolverListener
{
public function __construct(
private readonly UserProviderInterface $userProvider,
private readonly Crypt $crypt,
) {
}
public function onUserResolve(UserResolveEvent $event): void
{
try {
$user = $this->userProvider->loadUserByIdentifier($event->getUsername());
} catch (AuthenticationException $e) {
return;
}
if (!$user instanceof PasswordAuthenticatedUserInterface) {
return;
}
$passwordHash = $this->crypt->decrypt($user->getPassword());
if ($passwordHash !== md5($event->getPassword())) {
return;
}
$event->setUser($user);
}
}