From 5359dc7b51eaca1f01bb6fdbb2a5ae5acb2e45da Mon Sep 17 00:00:00 2001 From: amin Date: Thu, 11 Aug 2022 11:55:32 +0430 Subject: [PATCH 1/2] #fix make userProvider --- composer.json | 2 +- src/LaravelApiUserProviderServiceProvider.php | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 11af01d..79be13a 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "homepage": "https://github.com/amin3536/laravel-api-user-provider", "keywords": ["Laravel", "LaravelApiUserProvider"], "require": { - "illuminate/support": "~7|~8", + "illuminate/support": "~7|~8|~9", "guzzlehttp/guzzle": "^7.4", "laravel/passport": "^10.1", "ext-json": "*" diff --git a/src/LaravelApiUserProviderServiceProvider.php b/src/LaravelApiUserProviderServiceProvider.php index db68fe2..e1d5b1b 100644 --- a/src/LaravelApiUserProviderServiceProvider.php +++ b/src/LaravelApiUserProviderServiceProvider.php @@ -32,16 +32,15 @@ class LaravelApiUserProviderServiceProvider extends ServiceProvider public function boot() { $this->app->bind(HttpClient::class, function ($app) { - $config = $app->make('config'); - return new GuzzleHttpClient($this->getBaseUrl($config), $this->getTimeoutRequestToAuthServer($config)); + return new GuzzleHttpClient($this->getBaseUrl(), $this->getTimeoutRequestToAuthServer()); }); $this->app->bind(DeserializerInterface::class, function ($app) { return new Deserializer(); }); Auth::provider('api-provider', function ($app, array $config) { - return new ExternalUserProvider($app->make(HttpClient::class), $config['model'], $config['url'], $app->make(Deserializer::class)); + return $app->makeWith(ExternalUserProvider::class, ['model' => $config['model'], 'url' => $config['url']]); }); Auth::Extend('api-token', function ($app, $name, array $config) { @@ -67,14 +66,19 @@ public function boot() * * @return string|null */ - protected function getBaseUrl($config) + protected function getBaseUrl() { - return $config->get('auth.base-url'); + return $this->app['config']['auth.base-url']; } - protected function getTimeoutRequestToAuthServer($config) + /** + * Get the user provider configuration. + * + * @return string|null + */ + protected function getTimeoutRequestToAuthServer() { - return $config->get('auth.TimeoutForRequestAuthServer', 2); + return $this->app['config']->get('auth.TimeoutForRequestAuthServer', 2); } /** From 44e232f3f7d09e6b4c6217ccbde02ec3fb62af8d Mon Sep 17 00:00:00 2001 From: amin Date: Thu, 11 Aug 2022 12:21:43 +0430 Subject: [PATCH 2/2] #fix set header in new version of guzzle --- src/interactModule/GuzzleHttpClient.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/interactModule/GuzzleHttpClient.php b/src/interactModule/GuzzleHttpClient.php index d30b63a..3726593 100644 --- a/src/interactModule/GuzzleHttpClient.php +++ b/src/interactModule/GuzzleHttpClient.php @@ -44,10 +44,10 @@ public function setDefaultHeaders($defaultHeaders) * * @throws GuzzleException */ - public function sendRequest() + public function sendRequest( array $options = []) { try { - return $this->client->send($this->request); + return $this->client->send($this->request,$options); } catch (\GuzzleHttp\Exception\RequestException $e) { if ($e->hasResponse()) { return $e->getResponse(); @@ -65,9 +65,8 @@ public function sendRequest() */ public function createRequest($uri, $method = self::METHOD_GET, array $headers = [], $body = null, array $options = []): HttpClient { - $resultHeaders = ['headers' => array_merge($this->defaultHeaders, $headers)]; - $resultOptions = array_merge($resultHeaders, $options); - $this->request = new Request($method, $uri, $resultOptions, $body); + $resultHeaders = array_merge($this->defaultHeaders, $headers); + $this->request = new Request($method, $uri, $resultHeaders, $body); return $this; }