|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class Amazon |
|
4
|
|
|
* |
|
5
|
|
|
* @created 10.08.2018 |
|
6
|
|
|
* @author Smiley <[email protected]> |
|
7
|
|
|
* @copyright 2018 Smiley |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace chillerlan\OAuth\Providers; |
|
12
|
|
|
|
|
13
|
|
|
use chillerlan\HTTP\Utils\MessageUtil; |
|
14
|
|
|
use chillerlan\OAuth\Core\{CSRFToken, OAuth2Provider, ProviderException, TokenRefresh}; |
|
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
16
|
|
|
use function sprintf; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Amazon Login/OAuth |
|
20
|
|
|
* |
|
21
|
|
|
* @see https://login.amazon.com/ |
|
22
|
|
|
* @see https://developer.amazon.com/docs/login-with-amazon/documentation-overview.html |
|
23
|
|
|
* @see https://images-na.ssl-images-amazon.com/images/G/01/lwa/dev/docs/website-developer-guide._TTH_.pdf |
|
24
|
|
|
* @see https://images-na.ssl-images-amazon.com/images/G/01/mwsportal/doc/en_US/offamazonpayments/LoginAndPayWithAmazonIntegrationGuide._V335378063_.pdf |
|
25
|
|
|
*/ |
|
26
|
|
|
class Amazon extends OAuth2Provider implements CSRFToken, TokenRefresh{ |
|
27
|
|
|
|
|
28
|
|
|
public const SCOPE_PROFILE = 'profile'; |
|
29
|
|
|
public const SCOPE_PROFILE_USER_ID = 'profile:user_id'; |
|
30
|
|
|
public const SCOPE_POSTAL_CODE = 'postal_code'; |
|
31
|
|
|
|
|
32
|
|
|
protected string $authURL = 'https://www.amazon.com/ap/oa'; |
|
33
|
|
|
protected string $accessTokenURL = 'https://www.amazon.com/ap/oatoken'; |
|
34
|
|
|
protected string $apiURL = 'https://api.amazon.com'; |
|
35
|
|
|
protected ?string $apiDocs = 'https://login.amazon.com/'; |
|
36
|
|
|
protected ?string $applicationURL = 'https://sellercentral.amazon.com/hz/home'; |
|
37
|
|
|
|
|
38
|
|
|
protected array $defaultScopes = [ |
|
39
|
|
|
self::SCOPE_PROFILE, |
|
40
|
|
|
self::SCOPE_PROFILE_USER_ID, |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @inheritDoc |
|
45
|
|
|
*/ |
|
46
|
|
|
public function me():ResponseInterface{ |
|
47
|
|
|
$response = $this->request('/user/profile'); |
|
48
|
|
|
$status = $response->getStatusCode(); |
|
49
|
|
|
|
|
50
|
|
|
if($status === 200){ |
|
51
|
|
|
return $response; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$json = MessageUtil::decodeJSON($response); |
|
55
|
|
|
|
|
56
|
|
|
if(isset($json->error, $json->error_description)){ |
|
57
|
|
|
throw new ProviderException($json->error_description); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
throw new ProviderException(sprintf('user info error error HTTP/%s', $status)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|