Skip to content

Commit

Permalink
Merge pull request #27 from amin3536/develop
Browse files Browse the repository at this point in the history
update client guzzle
  • Loading branch information
amin3536 authored Aug 11, 2022
2 parents 7f8fb78 + 96b6bbd commit 8f8a919
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
Expand Down
18 changes: 11 additions & 7 deletions src/LaravelApiUserProviderServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/interactModule/GuzzleHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down

0 comments on commit 8f8a919

Please # to comment.