Skip to content

Commit c3ef6b6

Browse files
authored
Update Instagram provider to match Instagram api and work again. (#960)
1 parent f969160 commit c3ef6b6

File tree

2 files changed

+30
-43
lines changed

2 files changed

+30
-43
lines changed

Provider.php

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,27 @@
88

99
class Provider extends AbstractProvider
1010
{
11+
/**
12+
* Unique Provider Identifier.
13+
*/
1114
public const IDENTIFIER = 'INSTAGRAM';
1215

1316
/**
1417
* {@inheritdoc}
1518
*/
1619
protected $scopeSeparator = ' ';
1720

21+
/**
22+
* The user fields being requested.
23+
*
24+
* @var array
25+
*/
26+
protected $fields = ['account_type', 'id', 'username', 'media_count'];
27+
1828
/**
1929
* {@inheritdoc}
2030
*/
21-
protected $scopes = ['basic'];
31+
protected $scopes = ['user_profile'];
2232

2333
/**
2434
* {@inheritdoc}
@@ -44,24 +54,19 @@ protected function getTokenUrl()
4454
*/
4555
protected function getUserByToken($token)
4656
{
47-
$endpoint = '/users/self';
48-
$query = [
49-
'access_token' => $token,
50-
];
51-
$signature = $this->generateSignature($endpoint, $query);
52-
53-
$query['sig'] = $signature;
54-
$response = $this->getHttpClient()->get(
55-
'https://api.instagram.com/v1/users/self',
56-
[
57-
RequestOptions::QUERY => $query,
58-
RequestOptions::HEADERS => [
59-
'Accept' => 'application/json',
60-
],
61-
]
62-
);
57+
$meUrl = 'https://graph.instagram.com/me?access_token='.$token.'&fields='.implode(',', $this->fields);
58+
59+
if (!empty($this->clientSecret)) {
60+
$appSecretProof = hash_hmac('sha256', $token, $this->clientSecret);
61+
$meUrl .= '&appsecret_proof='.$appSecretProof;
62+
}
63+
$response = $this->getHttpClient()->get($meUrl, [
64+
RequestOptions::HEADERS => [
65+
'Accept' => 'application/json',
66+
],
67+
]);
6368

64-
return json_decode((string) $response->getBody(), true)['data'];
69+
return json_decode($response->getBody(), true);
6570
}
6671

6772
/**
@@ -70,9 +75,10 @@ protected function getUserByToken($token)
7075
protected function mapUserToObject(array $user)
7176
{
7277
return (new User())->setRaw($user)->map([
73-
'id' => $user['id'], 'nickname' => $user['username'],
74-
'name' => $user['full_name'], 'email' => null,
75-
'avatar' => $user['profile_picture'],
78+
'id' => $user['id'],
79+
'name' => $user['username'],
80+
'account_type' => $user['account_type'],
81+
'media_count' => $user['media_count'] ?? null,
7682
]);
7783
}
7884

@@ -96,23 +102,4 @@ protected function getTokenFields($code)
96102
'grant_type' => 'authorization_code',
97103
]);
98104
}
99-
100-
/**
101-
* Allows compatibility for signed API requests.
102-
*
103-
* @param string @endpoint
104-
* @param array $params
105-
*
106-
* @return string
107-
*/
108-
protected function generateSignature($endpoint, array $params)
109-
{
110-
$sig = $endpoint;
111-
ksort($params);
112-
foreach ($params as $key => $val) {
113-
$sig .= "|$key=$val";
114-
}
115-
116-
return hash_hmac('sha256', $sig, $this->clientSecret, false);
117-
}
118105
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ return Socialite::driver('instagram')->redirect();
4444
### Returned User fields
4545

4646
- ``id``
47-
- ``nickname``
48-
- ``name``
49-
- ``avatar``
47+
- ``username``
48+
- ``account_type``
49+
- ``media_count``

0 commit comments

Comments
 (0)