Skip to content

Commit

Permalink
Merge pull request #1 from Fooriva/master
Browse files Browse the repository at this point in the history
Symfony 4 migration
  • Loading branch information
FlorianKlee committed May 25, 2018
2 parents 581fba7 + b892f95 commit 3399794
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.
42 changes: 18 additions & 24 deletions Controller/FranceConnectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace KleeGroup\FranceConnectBundle\Controller;

use KleeGroup\FranceConnectBundle\Manager\ContextService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use KleeGroup\FranceConnectBundle\Manager\ContextServiceInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -16,21 +18,16 @@
*/
class FranceConnectController extends Controller
{

/**
* @return object|\Symfony\Bridge\Monolog\Logger
*/
private function getLogger()
{
return $this->get('logger');
}

/**
* @return ContextService|object
*/
private function getFCService()
/** @var LoggerInterface */
private $logger;

/** @var ContextServiceInterface */
private $contextService;

public function __construct(LoggerInterface $logger, ContextServiceInterface $contextService)
{
return $this->get('france_connect.service.context');
$this->logger = $logger;
$this->contextService = $contextService;
}

/**
Expand All @@ -39,9 +36,8 @@ private function getFCService()
*/
public function loginAction( )
{
$logger = $this->getLogger();
$logger->debug('Generating a URL to get the authorization code.');
$url = $this->getFCService()->generateAuthorizationURL();
$this->logger->debug('Generating a URL to get the authorization code.');
$url = $this->contextService->generateAuthorizationURL();

return $this->redirect($url);
}
Expand All @@ -54,10 +50,9 @@ public function loginAction( )
*/
public function checkAction(Request $request)
{
$logger = $this->getLogger();
$logger->debug('Callback intercept.');
$this->logger->debug('Callback intercept.');
$getParams = $request->query->all();
$this->getFCService()->getUserInfo($getParams);
$this->contextService->getUserInfo($getParams);

switch ($this->getParameter('france_connect.result_type')) {
case 'route' :
Expand All @@ -77,9 +72,8 @@ public function checkAction(Request $request)
*/
public function logoutAction()
{
$logger = $this->getLogger();
$logger->debug('Get Logout URL.');
$url = $this->getFCService()->generateLogoutURL();
$this->logger->debug('Get Logout URL.');
$url = $this->contextService->generateLogoutURL();

return $this->redirect($url);
}
Expand Down
4 changes: 2 additions & 2 deletions Manager/ContextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function __construct(
break;
}
} catch (RouteNotFoundException $e) {
throw new Exception("Callback route name is invalid", $e);
throw new Exception("Callback route name is invalid", 500, $e);
}

// Logout URL
Expand All @@ -166,7 +166,7 @@ public function __construct(
break;
}
} catch (RouteNotFoundException $e) {
throw new Exception("Logout route name is invalid", $e);
throw new Exception("Logout route name is invalid", 500, $e);
}

$this->proxyPort = $proxyPort;
Expand Down
8 changes: 8 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<defaults autowire="true" autoconfigure="true" public="false" />

<service
id="security.access.fc_authenticated_voter"
Expand Down Expand Up @@ -37,6 +38,13 @@
<argument id="providersKeys">%france_connect.providers_keys%</argument>
</service>

<service id="KleeGroup\FranceConnectBundle\Manager\ContextServiceInterface" alias="france_connect.service.context">
</service>

<prototype namespace="KleeGroup\FranceConnectBundle\Controller\" resource="../../Controller">
<tag name="controller.service_arguments" />
</prototype>

</services>


Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ france_connect:
* *client_id*: identifier provided by FranceConnect
* *client_secret*: secret identifier provided by FranceConnect
* *provider_base_url*: FranceConnect API URL. <strong>Must be change in production environment </b>
* *post_logout_route*: Route for redirecting user after logout
* *result_route*: Route for redirecting user after login on FranceConnect
* *logout_value*: Route for redirecting user after logout
* *result_value*: Route for redirecting user after login on FranceConnect
* *scopes*: scopes requested from FranceConnect. (Cf [documentation FranceConnect](https://franceconnect.gouv.fr/fournisseur-service#identite-pivot))
* *providers_keys* list of firewalls names. The token will be injected on these firewall

Expand Down
3 changes: 2 additions & 1 deletion Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@


use KleeGroup\FranceConnectBundle\DependencyInjection\Configuration;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Processor;

class ConfigurationTest extends \PHPUnit_Framework_TestCase
class ConfigurationTest extends TestCase
{
/**
* @test
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kleegroup/franceconnect-bundle",
"type": "symfony-bundle",
"description": "Symfony3 OpenID security extension franceconnect",
"description": "Symfony4 OpenID security extension franceconnect",
"keywords": ["Security", "OpenId", "Authentication"],
"homepage": "https://github.com/KleeGroup/FranceConnect-Symfony",
"license": "MIT",
Expand All @@ -12,13 +12,13 @@
}
],
"require": {
"php": ">=5.6.0",
"symfony/symfony": "3.*",
"php": "^7.1.3",
"symfony/framework-bundle": "^4",
"namshi/jose": "7.2.*",
"mashape/unirest-php": "3.*"
},
"require-dev": {
"phpunit/phpunit": "~5.4"
"phpunit/phpunit": "~7.1"
},
"autoload": {
"psr-0": { "KleeGroup\\FranceConnectBundle": "" }
Expand Down

0 comments on commit 3399794

Please sign in to comment.