access token on log in
This commit is contained in:
parent
89ed7049b9
commit
d2c20b9423
|
|
@ -4,6 +4,8 @@ namespace App\EventSubscriber;
|
||||||
|
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use League\Bundle\OAuth2ServerBundle\Model\AccessToken;
|
||||||
|
use League\Bundle\OAuth2ServerBundle\Model\Client;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
|
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
|
||||||
|
|
||||||
|
|
@ -30,8 +32,20 @@ class LoginSubscriber implements EventSubscriberInterface
|
||||||
if($user) {
|
if($user) {
|
||||||
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $user->getUserIdentifier()]);
|
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $user->getUserIdentifier()]);
|
||||||
$user->setLastConnection(new \DateTime('now', new \DateTimeZone('Europe/Paris')));
|
$user->setLastConnection(new \DateTime('now', new \DateTimeZone('Europe/Paris')));
|
||||||
|
|
||||||
|
$easySolution = $this->entityManager->getRepository(Client::class)->findOneBy(['name' => 'EasySolution']);
|
||||||
|
if($easySolution) {
|
||||||
|
$accessToken = new AccessToken(
|
||||||
|
identifier: bin2hex(random_bytes(40)), // Generate unique identifier
|
||||||
|
expiry: new \DateTimeImmutable('+1 hour', new \DateTimeZone('Europe/Paris')),
|
||||||
|
client: $easySolution,
|
||||||
|
userIdentifier: $user->getUserIdentifier(),
|
||||||
|
scopes: ['email profile openid apps:easySolutions'] // Empty array if no specific scopes needed
|
||||||
|
);
|
||||||
$this->entityManager->persist($user);
|
$this->entityManager->persist($user);
|
||||||
|
$this->entityManager->persist($accessToken);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue