Skip to content

Commit afa31e5

Browse files
schebwouterj
authored andcommitted
Add passport to AuthenticationTokenCreatedEvent
1 parent 5fe15e9 commit afa31e5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Authentication/AuthenticatorManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function authenticateUser(UserInterface $user, AuthenticatorInterface $au
7474
$token = $authenticator->createAuthenticatedToken($passport = new SelfValidatingPassport(new UserBadge(method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername(), function () use ($user) { return $user; }), $badges), $this->firewallName);
7575

7676
// announce the authenticated token
77-
$token = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($token))->getAuthenticatedToken();
77+
$token = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($token, $passport))->getAuthenticatedToken();
7878

7979
// authenticate this in the system
8080
return $this->handleAuthenticationSuccess($token, $passport, $request, $authenticator);
@@ -188,7 +188,7 @@ private function executeAuthenticator(AuthenticatorInterface $authenticator, Req
188188
$authenticatedToken = $authenticator->createAuthenticatedToken($passport, $this->firewallName);
189189

190190
// announce the authenticated token
191-
$authenticatedToken = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($authenticatedToken))->getAuthenticatedToken();
191+
$authenticatedToken = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($authenticatedToken, $passport))->getAuthenticatedToken();
192192

193193
if (true === $this->eraseCredentials) {
194194
$authenticatedToken->eraseCredentials();

Event/AuthenticationTokenCreatedEvent.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Http\Event;
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15+
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
1516
use Symfony\Contracts\EventDispatcher\Event;
1617

1718
/**
@@ -22,10 +23,12 @@
2223
class AuthenticationTokenCreatedEvent extends Event
2324
{
2425
private $authenticatedToken;
26+
private $passport;
2527

26-
public function __construct(TokenInterface $token)
28+
public function __construct(TokenInterface $token, PassportInterface $passport)
2729
{
2830
$this->authenticatedToken = $token;
31+
$this->passport = $passport;
2932
}
3033

3134
public function getAuthenticatedToken(): TokenInterface
@@ -37,4 +40,9 @@ public function setAuthenticatedToken(TokenInterface $authenticatedToken): void
3740
{
3841
$this->authenticatedToken = $authenticatedToken;
3942
}
43+
44+
public function getPassport(): PassportInterface
45+
{
46+
return $this->passport;
47+
}
4048
}

0 commit comments

Comments
 (0)