|
@@ -3,26 +3,39 @@
|
|
|
namespace Base\OAuthClientBundle\EventListener;
|
|
|
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
|
|
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
|
|
|
|
|
class RequestListener
|
|
|
{
|
|
|
|
|
|
+ /**
|
|
|
+ * @var TokenStorage
|
|
|
+ */
|
|
|
protected $securityTokenStorage;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
protected $client_id;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
protected $client_secret;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
protected $access_token_url;
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * @param SecurityTokenStorage $securityTokenStorage
|
|
|
+ * @param TokenStorage $securityTokenStorage
|
|
|
* @param string $client_id
|
|
|
* @param string $client_secret
|
|
|
* @param string $access_token_url
|
|
|
*/
|
|
|
- public function __construct($securityTokenStorage, $client_id, $client_secret, $access_token_url)
|
|
|
+ public function __construct(TokenStorage $securityTokenStorage, $client_id, $client_secret, $access_token_url)
|
|
|
{
|
|
|
$this->securityTokenStorage = $securityTokenStorage;
|
|
|
$this->client_id = $client_id;
|
|
@@ -32,6 +45,7 @@ class RequestListener
|
|
|
|
|
|
/**
|
|
|
* @param GetResponseEvent $event
|
|
|
+ *
|
|
|
* @return type
|
|
|
*/
|
|
|
public function onKernelRequest(GetResponseEvent $event)
|
|
@@ -59,11 +73,13 @@ class RequestListener
|
|
|
|
|
|
$newToken = json_decode($response, true);
|
|
|
|
|
|
- $token->setAccessToken($newToken['access_token']);
|
|
|
- $token->setRefreshToken($newToken['refresh_token']);
|
|
|
- $token->setExpiresIn($newToken['expires_in']);
|
|
|
-
|
|
|
- $this->securityTokenStorage->setToken($token);
|
|
|
+ if (isset($newToken['access_token']) && isset($newToken['refresh_token']) && isset($newToken['expires_in'])) {
|
|
|
+ $token->setAccessToken($newToken['access_token']);
|
|
|
+ $token->setRefreshToken($newToken['refresh_token']);
|
|
|
+ $token->setExpiresIn($newToken['expires_in']);
|
|
|
+
|
|
|
+ $this->securityTokenStorage->setToken($token);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return;
|