1 | <?php |
||
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 = ['user_profile']; |
||
22 | |||
23 | /** |
||
24 | * Default host |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $host = 'https://api.instagram.com'; |
||
29 | |||
30 | /** |
||
31 | * Default Graph API host |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $graphHost = 'https://graph.instagram.com'; |
||
36 | |||
37 | /** |
||
38 | * Gets host. |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | 4 | public function getHost() |
|
46 | |||
47 | /** |
||
48 | * Gets Graph API host. |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | 4 | public function getGraphHost() |
|
56 | |||
57 | /** |
||
58 | * Get the string used to separate scopes. |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | 6 | protected function getScopeSeparator() |
|
66 | |||
67 | /** |
||
68 | * Get authorization url to begin OAuth flow |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | 6 | public function getBaseAuthorizationUrl() |
|
76 | |||
77 | /** |
||
78 | * Get access token url to retrieve token |
||
79 | * |
||
80 | * @param array $params |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 12 | public function getBaseAccessTokenUrl(array $params) |
|
88 | |||
89 | /** |
||
90 | * Get provider url to fetch user details |
||
91 | * |
||
92 | * @param AccessToken $token |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | 2 | public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
100 | |||
101 | /** |
||
102 | * Returns an authenticated PSR-7 request instance. |
||
103 | * |
||
104 | * @param string $method |
||
105 | * @param string $url |
||
106 | * @param AccessToken|string $token |
||
107 | * @param array $options Any of "headers", "body", and "protocolVersion". |
||
108 | * |
||
109 | * @return \Psr\Http\Message\RequestInterface |
||
110 | */ |
||
111 | 4 | public function getAuthenticatedRequest($method, $url, $token, array $options = []) |
|
112 | { |
||
113 | 4 | $parsedUrl = parse_url($url); |
|
114 | 4 | $queryString = array(); |
|
115 | |||
116 | 4 | if (isset($parsedUrl['query'])) { |
|
117 | 2 | parse_str($parsedUrl['query'], $queryString); |
|
118 | } |
||
119 | |||
120 | 4 | if (!isset($queryString['access_token'])) { |
|
121 | 2 | $queryString['access_token'] = (string) $token; |
|
122 | } |
||
123 | |||
124 | 4 | $url = http_build_url($url, [ |
|
125 | 4 | 'query' => http_build_query($queryString), |
|
126 | ]); |
||
127 | |||
128 | 4 | return $this->createRequest($method, $url, null, $options); |
|
129 | } |
||
130 | |||
131 | /** |
||
132 | * Get the default scopes used by this provider. |
||
133 | * |
||
134 | * This should not be a complete list of all scopes, but the minimum |
||
135 | * required for the provider user interface! |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | 4 | protected function getDefaultScopes() |
|
143 | |||
144 | /** |
||
145 | * Check a provider response for errors. |
||
146 | * |
||
147 | * @throws IdentityProviderException |
||
148 | * @param ResponseInterface $response |
||
149 | * @param string $data Parsed response data |
||
150 | * @return void |
||
151 | */ |
||
152 | 10 | protected function checkResponse(ResponseInterface $response, $data) |
|
164 | |||
165 | /** |
||
166 | * Generate a user object from a successful user details request. |
||
167 | * |
||
168 | * @param array $response |
||
169 | * @param AccessToken $token |
||
170 | * @return ResourceOwnerInterface |
||
171 | */ |
||
172 | 2 | protected function createResourceOwner(array $response, AccessToken $token) |
|
176 | |||
177 | /** |
||
178 | * Sets host. |
||
179 | * |
||
180 | * @param string $host |
||
181 | * |
||
182 | * @return string |
||
183 | */ |
||
184 | 2 | public function setHost($host) |
|
190 | |||
191 | /** |
||
192 | * Sets Graph API host. |
||
193 | * |
||
194 | * @param string $host |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | 2 | public function setGraphHost($host) |
|
204 | } |
||
205 |