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