Skip to content
Permalink
Browse files

Adding ability to re-generate refresh token if expired

  • Loading branch information...
ghecquet committed Jun 27, 2017
1 parent 7f89442 commit b48b0b5e39eabe00786b51a88b675c9d706b6478
Showing with 43 additions and 2 deletions.
  1. +43 −2 core/src/plugins/core.access/src/Stream/OAuthStream.php
@@ -21,18 +21,25 @@
use Pydio\Core\Services\CacheService;
use Pydio\Core\Utils\FileHelper;
use GuzzleHttp\Event\ErrorEvent;
use GuzzleHttp\Event\RequestEvents;
use GuzzleHttp\Event\SubscriberInterface;
use GuzzleHttp\Message\Response;
/**
* Class OAuthStream
* @package Pydio\Access\Core\Stream
*/
class OAuthStream implements StreamInterface
class OAuthStream implements StreamInterface, SubscriberInterface
{
use StreamDecoratorTrait;
/** @var ContextInterface Context */
private $context;
/**
* OAuthStream constructor.
* @param StreamInterface $stream
@@ -135,12 +142,24 @@ public function __construct(
Stream::addContextOption($this->context, [
"auth" => "oauth2",
"subscribers" => [$oauth2]
"subscribers" => [$oauth2, $this]
]);
$this->stream = $stream;
}
/**
* Get the list of events this subscriber is being triggered on
*
* @return array Events
*/
public function getEvents()
{
return [
'error' => ['onError', RequestEvents::EARLY],
];
}
/**
* @param ContextInterface $ctx
* @return array
@@ -227,4 +246,26 @@ private function setTokens($accessToken, $refreshToken)
public function getContents() {
return $this->stream->getContents();
}
/**
* Handle the before trigger
*
* @param ErrorEvent $event
* @internal param ErrorEvent $e
*/
public function onError(ErrorEvent $event)
{
$response = $event->getResponse();
if ($response && 401 == $response->getStatusCode()) {
$request = $event->getRequest();
if ($request->getConfig()->get('auth') == 'oauth2' && $request->getConfig()->get('retried')) {
$this->setTokens("", "");
//$request->getConfig()->set('retried', false);
//$event->intercept($event->getClient()->send($request));
}
}
}
}

0 comments on commit b48b0b5

Please sign in to comment.
You can’t perform that action at this time.