forked from hwi/HWIOAuthBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hwi#1592 from dmaicher/symfony_5_support
Symfony 5 compatibility
- Loading branch information
Showing
17 changed files
with
418 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,7 @@ | |
use HWI\Bundle\OAuthBundle\Security\Core\Exception\AccountNotLinkedException; | ||
use HWI\Bundle\OAuthBundle\Security\Http\ResourceOwnerMapLocator; | ||
use HWI\Bundle\OAuthBundle\Security\OAuthUtils; | ||
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait; | ||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||
use Symfony\Component\DependencyInjection\ContainerAwareTrait; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; | ||
use Symfony\Component\Form\Extension\Core\Type\FormType; | ||
use Symfony\Component\Form\FormInterface; | ||
|
@@ -40,11 +38,8 @@ | |
/** | ||
* @author Alexander <[email protected]> | ||
*/ | ||
final class ConnectController implements ContainerAwareInterface | ||
final class ConnectController extends AbstractController | ||
{ | ||
use ContainerAwareTrait; | ||
use ControllerTrait; | ||
|
||
/** | ||
* @var OAuthUtils | ||
*/ | ||
|
@@ -55,10 +50,6 @@ final class ConnectController implements ContainerAwareInterface | |
*/ | ||
private $resourceOwnerMapLocator; | ||
|
||
/** | ||
* @param OAuthUtils $oauthUtils | ||
* @param ResourceOwnerMapLocator $resourceOwnerMapLocator | ||
*/ | ||
public function __construct(OAuthUtils $oauthUtils, ResourceOwnerMapLocator $resourceOwnerMapLocator) | ||
{ | ||
$this->oauthUtils = $oauthUtils; | ||
|
@@ -80,12 +71,12 @@ public function __construct(OAuthUtils $oauthUtils, ResourceOwnerMapLocator $res | |
*/ | ||
public function registrationAction(Request $request, $key) | ||
{ | ||
$connect = $this->container->getParameter('hwi_oauth.connect'); | ||
$connect = $this->getParameter('hwi_oauth.connect'); | ||
if (!$connect) { | ||
throw new NotFoundHttpException(); | ||
} | ||
|
||
$hasUser = $this->isGranted($this->container->getParameter('hwi_oauth.grant_rule')); | ||
$hasUser = $this->isGranted($this->getParameter('hwi_oauth.grant_rule')); | ||
if ($hasUser) { | ||
throw new AccessDeniedException('Cannot connect already registered account.'); | ||
} | ||
|
@@ -110,14 +101,14 @@ public function registrationAction(Request $request, $key) | |
; | ||
|
||
/* @var $form FormInterface */ | ||
$form = $this->container->get('hwi_oauth.registration.form.factory')->createForm(); | ||
$form = $this->get('hwi_oauth.registration.form.factory')->createForm(); | ||
|
||
$formHandler = $this->container->get('hwi_oauth.registration.form.handler'); | ||
$formHandler = $this->get('hwi_oauth.registration.form.handler'); | ||
if ($formHandler->process($request, $form, $userInformation)) { | ||
$event = new FormEvent($form, $request); | ||
$this->dispatch($event, HWIOAuthEvents::REGISTRATION_SUCCESS); | ||
|
||
$this->container->get('hwi_oauth.account.connector')->connect($form->getData(), $userInformation); | ||
$this->get('hwi_oauth.account.connector')->connect($form->getData(), $userInformation); | ||
|
||
// Authenticate the user | ||
$this->authenticateUser($request, $form->getData(), $error->getResourceOwnerName(), $error->getAccessToken()); | ||
|
@@ -172,12 +163,12 @@ public function registrationAction(Request $request, $key) | |
*/ | ||
public function connectServiceAction(Request $request, $service) | ||
{ | ||
$connect = $this->container->getParameter('hwi_oauth.connect'); | ||
$connect = $this->getParameter('hwi_oauth.connect'); | ||
if (!$connect) { | ||
throw new NotFoundHttpException(); | ||
} | ||
|
||
$hasUser = $this->isGranted($this->container->getParameter('hwi_oauth.grant_rule')); | ||
$hasUser = $this->isGranted($this->getParameter('hwi_oauth.grant_rule')); | ||
if (!$hasUser) { | ||
throw new AccessDeniedException('Cannot connect an account.'); | ||
} | ||
|
@@ -209,15 +200,15 @@ public function connectServiceAction(Request $request, $service) | |
|
||
// Redirect to the login path if the token is empty (Eg. User cancelled auth) | ||
if (null === $accessToken) { | ||
if ($this->container->getParameter('hwi_oauth.failed_use_referer') && $targetPath = $this->getTargetPath($session)) { | ||
if ($this->getParameter('hwi_oauth.failed_use_referer') && $targetPath = $this->getTargetPath($session)) { | ||
return $this->redirect($targetPath); | ||
} | ||
|
||
return $this->redirectToRoute($this->container->getParameter('hwi_oauth.failed_auth_path')); | ||
return $this->redirectToRoute($this->getParameter('hwi_oauth.failed_auth_path')); | ||
} | ||
|
||
// Show confirmation page? | ||
if (!$this->container->getParameter('hwi_oauth.connect.confirmation')) { | ||
if (!$this->getParameter('hwi_oauth.connect.confirmation')) { | ||
return $this->getConfirmationResponse($request, $accessToken, $service); | ||
} | ||
|
||
|
@@ -247,6 +238,12 @@ public function connectServiceAction(Request $request, $service) | |
]); | ||
} | ||
|
||
protected function getParameter(string $name) | ||
{ | ||
// Symfony 3.4 compat | ||
return $this->container->getParameter($name); | ||
} | ||
|
||
/** | ||
* Get a resource owner by name. | ||
* | ||
|
@@ -258,7 +255,7 @@ public function connectServiceAction(Request $request, $service) | |
*/ | ||
private function getResourceOwnerByName($name) | ||
{ | ||
foreach ($this->container->getParameter('hwi_oauth.firewall_names') as $firewall) { | ||
foreach ($this->getParameter('hwi_oauth.firewall_names') as $firewall) { | ||
if (!$this->resourceOwnerMapLocator->has($firewall)) { | ||
continue; | ||
} | ||
|
@@ -284,7 +281,7 @@ private function getResourceOwnerByName($name) | |
private function authenticateUser(Request $request, UserInterface $user, $resourceOwnerName, $accessToken, $fakeLogin = true) | ||
{ | ||
try { | ||
$userChecker = $this->container->get('hwi_oauth.user_checker'); | ||
$userChecker = $this->get('hwi_oauth.user_checker'); | ||
$userChecker->checkPreAuth($user); | ||
$userChecker->checkPostAuth($user); | ||
} catch (AccountStatusException $e) { | ||
|
@@ -319,7 +316,7 @@ private function getTargetPath(?SessionInterface $session) | |
return null; | ||
} | ||
|
||
foreach ($this->container->getParameter('hwi_oauth.firewall_names') as $providerKey) { | ||
foreach ($this->getParameter('hwi_oauth.firewall_names') as $providerKey) { | ||
$sessionKey = '_security.'.$providerKey.'.target_path'; | ||
if ($session->has($sessionKey)) { | ||
return $session->get($sessionKey); | ||
|
@@ -341,7 +338,7 @@ private function getTargetPath(?SessionInterface $session) | |
private function getConfirmationResponse(Request $request, array $accessToken, $service) | ||
{ | ||
/** @var $currentToken OAuthToken */ | ||
$currentToken = $this->container->get('security.token_storage')->getToken(); | ||
$currentToken = $this->get('security.token_storage')->getToken(); | ||
/** @var $currentUser UserInterface */ | ||
$currentUser = $currentToken->getUser(); | ||
|
||
|
@@ -353,7 +350,7 @@ private function getConfirmationResponse(Request $request, array $accessToken, $ | |
$event = new GetResponseUserEvent($currentUser, $request); | ||
$this->dispatch($event, HWIOAuthEvents::CONNECT_CONFIRMED); | ||
|
||
$this->container->get('hwi_oauth.account.connector')->connect($currentUser, $userInformation); | ||
$this->get('hwi_oauth.account.connector')->connect($currentUser, $userInformation); | ||
|
||
if ($currentToken instanceof OAuthToken) { | ||
// Update user token with new details | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the HWIOAuthBundle package. | ||
* | ||
* (c) Hardware Info <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace HWI\Bundle\OAuthBundle\Event; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent; | ||
|
||
if (class_exists(Event::class)) { | ||
// Symfony < 5 | ||
abstract class AbstractEvent extends Event | ||
{ | ||
} | ||
} else { | ||
// Symfony 5 | ||
abstract class AbstractEvent extends ContractsEvent | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.