chamilo/chamilo-lms

View on GitHub
src/CoreBundle/Controller/OAuth2/AbstractProviderController.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

/* For licensing terms, see /license.txt */

declare(strict_types=1);

namespace Chamilo\CoreBundle\Controller\OAuth2;

use Chamilo\CoreBundle\ServiceHelper\AuthenticationConfigHelper;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

abstract class AbstractProviderController extends AbstractController
{
    protected function getStartResponse(
        string $providerName,
        ClientRegistry $clientRegistry,
        AuthenticationConfigHelper $authenticationConfigHelper,
    ): Response {
        if (!$authenticationConfigHelper->isEnabled($providerName)) {
            throw $this->createAccessDeniedException();
        }

        return $clientRegistry->getClient($providerName)->redirect();
    }
}