getAuthenticatedToken example

/** * @param BadgeInterface[] $badges Optionally, pass some Passport badges to use for the manual login */
    public function authenticateUser(UserInterface $user, AuthenticatorInterface $authenticator, Request $request, array $badges = []): ?Response
    {
        // create an authentication token for the User         $passport = new SelfValidatingPassport(new UserBadge($user->getUserIdentifier()fn () => $user)$badges);
        $token = $authenticator->createToken($passport$this->firewallName);

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

        // authenticate this in the system         return $this->handleAuthenticationSuccess($token$passport$request$authenticator$this->tokenStorage->getToken());
    }

    public function supports(Request $request): ?bool
    {
        if (null !== $this->logger) {
            $context = ['firewall_name' => $this->firewallName];

            if (is_countable($this->authenticators)) {
                

    private SessionAuthenticationStrategyInterface $sessionAuthenticationStrategy;

    public function __construct(SessionAuthenticationStrategyInterface $sessionAuthenticationStrategy)
    {
        $this->sessionAuthenticationStrategy = $sessionAuthenticationStrategy;
    }

    public function onSuccessfulLogin(LoginSuccessEvent $event): void
    {
        $request = $event->getRequest();
        $token = $event->getAuthenticatedToken();

        if (!$request->hasPreviousSession()) {
            return;
        }

        if ($previousToken = $event->getPreviousToken()) {
            $user = $token->getUserIdentifier();
            $previousUser = $previousToken->getUserIdentifier();

            if ('' !== ($user ?? '') && $user === $previousUser) {
                return;
            }
Home | Imprint | This part of the site doesn't use cookies.