1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AdamPaterson\OAuth2\Client\Provider; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
6
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
7
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
8
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
9
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
11
|
|
|
|
12
|
|
|
class Imgur extends AbstractProvider |
13
|
|
|
{ |
14
|
|
|
use BearerAuthorizationTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Get authorization url to begin OAuth flow |
18
|
|
|
* |
19
|
|
|
* @return string |
20
|
|
|
*/ |
21
|
6 |
|
public function getBaseAuthorizationUrl() |
22
|
|
|
{ |
23
|
6 |
|
return 'https://api.imgur.com/oauth2/authorize'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Get access token url to retrieve token |
28
|
|
|
* |
29
|
|
|
* @param array $params |
30
|
|
|
* |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
12 |
|
public function getBaseAccessTokenUrl(array $params) |
34
|
|
|
{ |
35
|
12 |
|
return 'https://api.imgur.com/oauth2/token'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get provider url to fetch user details |
40
|
|
|
* |
41
|
|
|
* @param AccessToken $token |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
3 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
46
|
|
|
{ |
47
|
3 |
|
return 'https://api.imgur.com/3/account/me'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the default scopes used by this provider. |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
6 |
|
protected function getDefaultScopes() |
56
|
|
|
{ |
57
|
6 |
|
return []; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Check a provider response for errors. |
62
|
|
|
* |
63
|
|
|
* @param ResponseInterface $response |
64
|
|
|
* @param array|string $data |
65
|
|
|
* |
66
|
|
|
* @throws IdentityProviderException |
67
|
|
|
*/ |
68
|
9 |
|
protected function checkResponse(ResponseInterface $response, $data) |
69
|
|
|
{ |
70
|
9 |
|
if ($response->getStatusCode() >= 400) { |
71
|
3 |
|
throw new IdentityProviderException( |
72
|
3 |
|
$data['error'] ?: $response->getReasonPhrase(), |
73
|
3 |
|
$response->getStatusCode(), |
74
|
2 |
|
$response |
|
|
|
|
75
|
1 |
|
); |
76
|
|
|
} |
77
|
6 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Generate a user object from a successful user details request. |
81
|
|
|
* |
82
|
|
|
* @param array $response |
83
|
|
|
* @param AccessToken $token |
84
|
|
|
* |
85
|
|
|
* @return League\OAuth2\Client\Provider\ResourceOwnerInterface |
86
|
|
|
*/ |
87
|
3 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
88
|
|
|
{ |
89
|
3 |
|
return new ImgurResourceOwner($response); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
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: