Skip to content

[Security] Add passport to AuthenticationTokenCreatedEvent #40840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Security/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The CHANGELOG for version 5.4 and newer can be found in the security sub-package
5.3
---

* Add `getPassport()` method and a second `$passport` constructor argument to `AuthenticationTokenCreatedEvent`
* The authenticator system is no longer experimental
* Login Link functionality is no longer experimental
* Add `RememberMeConditionsListener` to check if remember me is requested and supported, and set priority of `RememberMeListener` to -63
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function authenticateUser(UserInterface $user, AuthenticatorInterface $au
$token = $authenticator->createAuthenticatedToken($passport = new SelfValidatingPassport(new UserBadge(method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername(), function () use ($user) { return $user; }), $badges), $this->firewallName);

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

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

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

if (true === $this->eraseCredentials) {
$authenticatedToken->eraseCredentials();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Http\Event;

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
use Symfony\Contracts\EventDispatcher\Event;

/**
Expand All @@ -22,10 +23,12 @@
class AuthenticationTokenCreatedEvent extends Event
{
private $authenticatedToken;
private $passport;

public function __construct(TokenInterface $token)
public function __construct(TokenInterface $token, PassportInterface $passport)
{
$this->authenticatedToken = $token;
$this->passport = $passport;
}

public function getAuthenticatedToken(): TokenInterface
Expand All @@ -37,4 +40,9 @@ public function setAuthenticatedToken(TokenInterface $authenticatedToken): void
{
$this->authenticatedToken = $authenticatedToken;
}

public function getPassport(): PassportInterface
{
return $this->passport;
}
}