|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace Base\OAuthClientBundle\EventListener;
|
|
namespace Base\OAuthClientBundle\EventListener;
|
|
|
|
|
|
|
|
+use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
|
|
|
|
|
@@ -30,14 +31,15 @@ class RequestListener
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param TokenStorage $securityTokenStorage
|
|
|
|
|
|
+ * @param ContainerInterface $serviceContainer
|
|
* @param string $client_id
|
|
* @param string $client_id
|
|
* @param string $client_secret
|
|
* @param string $client_secret
|
|
* @param string $access_token_url
|
|
* @param string $access_token_url
|
|
*/
|
|
*/
|
|
- public function __construct(TokenStorage $securityTokenStorage, $client_id, $client_secret, $access_token_url)
|
|
|
|
|
|
+ public function __construct($serviceContainer, $client_id, $client_secret, $access_token_url)
|
|
{
|
|
{
|
|
- $this->securityTokenStorage = $securityTokenStorage;
|
|
|
|
|
|
+ $this->container = $serviceContainer;
|
|
|
|
+ $this->securityTokenStorage = $serviceContainer->get('security.token_storage');
|
|
$this->client_id = $client_id;
|
|
$this->client_id = $client_id;
|
|
$this->client_secret = $client_secret;
|
|
$this->client_secret = $client_secret;
|
|
$this->access_token_url = $access_token_url;
|
|
$this->access_token_url = $access_token_url;
|
|
@@ -53,7 +55,22 @@ class RequestListener
|
|
if (!$event->isMasterRequest()) {
|
|
if (!$event->isMasterRequest()) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ // Autologin por GET parameters
|
|
|
|
+ $request = $event->getRequest();
|
|
|
|
+ $authorizationUrl = $this->container->get('hwi_oauth.security.oauth_utils')->getAuthorizationUrl($request, 'login');
|
|
|
|
+ $username = $request->get('username');
|
|
|
|
+ $plainPassword = $request->get('password');
|
|
|
|
+ if ($username && $plainPassword) {
|
|
|
|
+ $event->setResponse(new RedirectResponse($authorizationUrl . "&username={$username}&password={$plainPassword}"));
|
|
|
|
+
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ } catch(\Exception $ex) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
$token = $this->securityTokenStorage->getToken();
|
|
$token = $this->securityTokenStorage->getToken();
|
|
if ($token && method_exists($token, 'isExpired') && $token->isExpired()) {
|
|
if ($token && method_exists($token, 'isExpired') && $token->isExpired()) {
|
|
$parameters = array(
|
|
$parameters = array(
|