63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\User\Services\FIB;
|
|
|
|
use Exception;
|
|
use Illuminate\Http\Client\ConnectionException;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class AuthorizationService
|
|
{
|
|
protected string $url;
|
|
protected string $channelName;
|
|
protected array $inputParameters;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->url = config('fib.authorization.url');
|
|
$this->channelName = '';
|
|
}
|
|
|
|
public function setInputParameters(): void
|
|
{
|
|
$this->inputParameters = [
|
|
'client_id' => config('fib.authorization.client_id'),
|
|
'client_secret' => config('fib.authorization.client_secret'),
|
|
'grant_type' => 'client_credentials',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function run(): array
|
|
{
|
|
try {
|
|
return $this->sendRequest();
|
|
}
|
|
catch (Exception $e) {
|
|
Log::channel($this->channelName)
|
|
->error(get_class($this),
|
|
[
|
|
'message' => $e->getMessage(),
|
|
]
|
|
);
|
|
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @throws ConnectionException
|
|
*/
|
|
public function sendRequest(): array
|
|
{
|
|
return Http::withHeaders(['Content-Type' => 'application/json'])
|
|
->throw()
|
|
->withoutVerifying()
|
|
->post($this->url, $this->inputParameters)
|
|
->json();
|
|
}
|
|
}
|