1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\OAuth2\Client\Provider; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
6
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
|
9
|
|
|
class Instagram extends AbstractProvider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string Key used in a token response to identify the resource owner. |
13
|
|
|
*/ |
14
|
|
|
const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'user.id'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Default scopes |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
public $defaultScopes = ['basic']; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get the string used to separate scopes. |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
6 |
|
protected function getScopeSeparator() |
29
|
|
|
{ |
30
|
6 |
|
return ' '; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get authorization url to begin OAuth flow |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
6 |
|
public function getBaseAuthorizationUrl() |
39
|
|
|
{ |
40
|
6 |
|
return 'https://api.instagram.com/oauth/authorize'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get access token url to retrieve token |
45
|
|
|
* |
46
|
|
|
* @param array $params |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
12 |
|
public function getBaseAccessTokenUrl(array $params) |
51
|
|
|
{ |
52
|
12 |
|
return 'https://api.instagram.com/oauth/access_token'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get provider url to fetch user details |
57
|
|
|
* |
58
|
|
|
* @param AccessToken $token |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
2 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
63
|
|
|
{ |
64
|
2 |
|
return 'https://api.instagram.com/v1/users/self?access_token='.$token; |
65
|
|
|
} |
66
|
|
|
|
67
|
4 |
|
public function getAuthenticatedRequest($method, $url, $token, array $options = []) |
68
|
|
|
{ |
69
|
4 |
|
$parsedUrl = \parse_url($url); |
70
|
4 |
|
$queryString = array(); |
71
|
|
|
|
72
|
4 |
|
if (isset($parsedUrl['query'])) { |
73
|
2 |
|
parse_str($parsedUrl['query'], $queryString); |
74
|
2 |
|
} |
75
|
|
|
|
76
|
4 |
|
if (!isset($queryString['access_token'])) { |
77
|
2 |
|
$queryString['access_token'] = (string) $token; |
78
|
2 |
|
} |
79
|
|
|
|
80
|
4 |
|
$url = \http_build_url($url, [ |
81
|
4 |
|
'query' => \http_build_query($queryString), |
82
|
4 |
|
]); |
83
|
|
|
|
84
|
4 |
|
return $this->createRequest($method, $url, null, $options); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get the default scopes used by this provider. |
89
|
|
|
* |
90
|
|
|
* This should not be a complete list of all scopes, but the minimum |
91
|
|
|
* required for the provider user interface! |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
4 |
|
protected function getDefaultScopes() |
96
|
|
|
{ |
97
|
4 |
|
return $this->defaultScopes; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Check a provider response for errors. |
102
|
|
|
* |
103
|
|
|
* @link https://instagram.com/developer/endpoints/ |
104
|
|
|
* @throws IdentityProviderException |
105
|
|
|
* @param ResponseInterface $response |
106
|
|
|
* @param string $data Parsed response data |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
10 |
|
protected function checkResponse(ResponseInterface $response, $data) |
110
|
|
|
{ |
111
|
|
|
// standard error response format |
112
|
10 |
|
if (!empty($data['meta']['error_type'])) { |
113
|
2 |
|
throw new IdentityProviderException( |
114
|
2 |
|
$data['meta']['error_message'] ?: $response->getReasonPhrase(), |
115
|
2 |
|
$data['meta']['code'] ?: $response->getStatusCode(), |
116
|
|
|
$response |
|
|
|
|
117
|
2 |
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
// OAuthException error response format |
121
|
8 |
|
if (!empty($data['error_type'])) { |
122
|
2 |
|
throw new IdentityProviderException( |
123
|
2 |
|
$data['error_message'] ?: $response->getReasonPhrase(), |
124
|
2 |
|
$data['code'] ?: $response->getStatusCode(), |
125
|
|
|
$response |
|
|
|
|
126
|
2 |
|
); |
127
|
|
|
} |
128
|
6 |
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Generate a user object from a successful user details request. |
132
|
|
|
* |
133
|
|
|
* @param array $response |
134
|
|
|
* @param AccessToken $token |
135
|
|
|
* @return \League\OAuth2\Client\Provider\ResourceOwnerInterface |
136
|
|
|
*/ |
137
|
2 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
138
|
|
|
{ |
139
|
2 |
|
return new InstagramResourceOwner($response); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
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: