OpenXE/classes/Modules/AmazonVendorDF/Service/TokenService.php

42 lines
1.2 KiB
PHP
Raw Normal View History

2021-05-21 08:49:41 +02:00
<?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);
}
}