mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-29 08:00:28 +01:00
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Xentral\Modules\AmazonVendorDF\Service;
|
||
|
|
||
|
use GuzzleHttp\ClientInterface;
|
||
|
use GuzzleHttp\Exception\BadResponseException;
|
||
|
use Xentral\Modules\AmazonVendorDF\Data\Token;
|
||
|
use Xentral\Modules\AmazonVendorDF\Exception\IssueTokenException;
|
||
|
|
||
|
class TokenService
|
||
|
{
|
||
|
/** @var ClientInterface */
|
||
|
private $client;
|
||
|
|
||
|
public function __construct(ClientInterface $client)
|
||
|
{
|
||
|
$this->client = $client;
|
||
|
}
|
||
|
|
||
|
public function requestToken(string $refreshToken, string $clientId, string $clientSecret)
|
||
|
{
|
||
|
try {
|
||
|
$response = $this->client->request(
|
||
|
'POST',
|
||
|
'https://api.amazon.com/auth/o2/token',
|
||
|
[
|
||
|
'form_params' => [
|
||
|
'grant_type' => 'refresh_token',
|
||
|
'refresh_token' => $refreshToken,
|
||
|
'client_id' => $clientId,
|
||
|
'client_secret' => $clientSecret,
|
||
|
],
|
||
|
]
|
||
|
);
|
||
|
}catch (BadResponseException $badResponseException){
|
||
|
throw IssueTokenException::fromResponse($badResponseException->getResponse());
|
||
|
}
|
||
|
|
||
|
return Token::fromResponse($response);
|
||
|
}
|
||
|
}
|