1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Gumroad OAuth2 Provider |
5
|
|
|
* (c) alofoxx |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Alofoxx\OAuth2\Client\Provider; |
12
|
|
|
|
13
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
14
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
15
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
16
|
|
|
use Alofoxx\OAuth2\Client\Provider\Exception\GumroadIdentityProviderException; |
17
|
|
|
use Psr\Http\Message\ResponseInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Gumroad provider. |
21
|
|
|
* |
22
|
|
|
* @author alofoxx <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class Gumroad extends AbstractProvider |
25
|
|
|
{ |
26
|
|
|
use BearerAuthorizationTrait; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* API Domain |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $apiDomain = 'https://gumroad.com'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get authorization URL to begin OAuth flow |
37
|
|
|
* Note: Gumroad does not use /oauth2/ for url path of OAuth2! |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
9 |
|
public function getBaseAuthorizationUrl() |
42
|
|
|
{ |
43
|
9 |
|
return $this->apiDomain.'/oauth/authorize'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get access token URL to retrieve token |
48
|
|
|
* Note: Gumroad does not use /oauth2/ for url path of OAuth2! |
49
|
|
|
* |
50
|
|
|
* @param array $params |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
15 |
|
public function getBaseAccessTokenUrl(array $params) |
55
|
|
|
{ |
56
|
15 |
|
return $this->apiDomain.'/oauth/token'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get provider URL to retrieve user details |
61
|
|
|
* |
62
|
|
|
* @param AccessToken $token |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
3 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
67
|
|
|
{ |
68
|
3 |
|
return $this->apiDomain.'/api/v2/user'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns the string that should be used to separate scopes when building |
73
|
|
|
* the URL for requesting an access token. |
74
|
|
|
* |
75
|
|
|
* Discord's scope separator is space (%20) |
76
|
|
|
* |
77
|
|
|
* @return string Scope separator |
78
|
|
|
*/ |
79
|
9 |
|
protected function getScopeSeparator() |
80
|
|
|
{ |
81
|
9 |
|
return ' '; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the default scopes used by this provider. |
86
|
|
|
* |
87
|
|
|
* This should not be a complete list of all scopes, but the minimum |
88
|
|
|
* required for the provider user interface! |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
6 |
|
protected function getDefaultScopes() |
93
|
|
|
{ |
94
|
6 |
|
return ['view_sales']; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Check a provider response for errors. |
99
|
|
|
* |
100
|
|
|
* @throws \League\OAuth2\Client\Provider\Exception\IdentityProviderException |
101
|
|
|
* @param ResponseInterface $response |
102
|
|
|
* @param array $data Parsed response data |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
12 |
|
protected function checkResponse(ResponseInterface $response, $data) |
106
|
|
|
{ |
107
|
12 |
|
if ($response->getStatusCode() >= 400) { |
108
|
3 |
|
throw GumroadIdentityProviderException::clientException($response, $data); |
109
|
9 |
|
} elseif (isset($data['error'])) { |
110
|
3 |
|
throw GumroadIdentityProviderException::oauthException($response, $data); |
|
|
|
|
111
|
|
|
} |
112
|
6 |
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Generate a user object from a successful user details request. |
116
|
|
|
* |
117
|
|
|
* @param array $response |
118
|
|
|
* @param AccessToken $token |
119
|
|
|
* @return \League\OAuth2\Client\Provider\ResourceOwnerInterface |
120
|
|
|
*/ |
121
|
3 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
122
|
|
|
{ |
123
|
3 |
|
return new GumroadResourceOwner($response); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: