Covivo/mobicoop

View on GitHub
api/src/Security/LoginAuthenticator.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
/**
 * Copyright (c) 2022, MOBICOOP. All rights reserved.
 * This project is dual licensed under AGPL and proprietary licence.
 ***************************
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Affero General Public License as
 *    published by the Free Software Foundation, either version 3 of the
 *    License, or (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with this program.  If not, see <gnu.org/licenses>.
 ***************************
 *    Licence MOBICOOP described in the file
 *    LICENSE
 */

namespace App\Security;

use App\User\Entity\User;
use App\User\Service\SsoManager;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;

/**
 * @author Maxime Bardot <maxime.bardot@mobicoop.org>
 */
class LoginAuthenticator
{
    private $ssoManager;

    public function __construct(SsoManager $ssoManager)
    {
        $this->ssoManager = $ssoManager;
    }

    public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
    {
        $data = $event->getData();
        $user = $event->getUser();

        if (!$user instanceof User) {
            return;
        }

        // Why is it there ? This LoginAuthenticator doesn't really care of sso logout url right ?
        // If it's mandatory, how to choose the right url ? Only the first provider because we just say so ?
        // Until an anwser I disable this.

        // if (!is_null($user->getSsoProvider())) {
        //     $logoutUrl = $this->ssoManager->getSsoLogoutUrl($user);
        //     if ($logoutUrl) {
        //         $data['logoutUrl'] = $this->ssoManager->getSsoLogoutUrl($user);
        //     }
        // }

        $event->setData($data);
    }
}