diff --git a/.gitignore b/.gitignore index aaa3129..6cd00bc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build composer.lock vendor .env +.idea \ No newline at end of file diff --git a/src/Http/Middleware/AuthMiddleware.php b/src/Http/Middleware/AuthMiddleware.php index cc4f839..c83de38 100644 --- a/src/Http/Middleware/AuthMiddleware.php +++ b/src/Http/Middleware/AuthMiddleware.php @@ -3,6 +3,7 @@ namespace Larabros\Elogram\Http\Middleware; use GuzzleHttp\Psr7\Uri; +use League\OAuth2\Client\Token\AccessToken; use Psr\Http\Message\RequestInterface; /** @@ -30,10 +31,16 @@ public function __invoke(RequestInterface $request, array $options) return $next($request, $options); } + $accessToken = $this->config->get('access_token'); + + if (!($accessToken instanceof AccessToken)) { + $accessToken = new AccessToken(json_decode($accessToken , true)); + } + $uri = Uri::withQueryValue( $request->getUri(), 'access_token', - $this->config->get('access_token')->getToken() + $accessToken->getToken() ); return parent::__invoke(