Skip to content

Commit e802fc3

Browse files
eh-stevefaustbrian
authored andcommitted
Compatibility for signed Instagram API requests (#19)
* Compatibility for signed Instagram API requests * StyleCI * StyleCI * StyleCI
1 parent 4a220dd commit e802fc3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Provider.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ protected function getTokenUrl()
4646
*/
4747
protected function getUserByToken($token)
4848
{
49+
$endpoint = '/users/self';
50+
$query = [
51+
'access_token' => $token,
52+
];
53+
$signature = $this->generateSignature($endpoint, $query);
54+
55+
$query['sig'] = $signature;
4956
$response = $this->getHttpClient()->get(
50-
'https://api.instagram.com/v1/users/self?access_token='.$token, [
57+
'https://api.instagram.com/v1/users/self', [
58+
'query' => $query,
5159
'headers' => [
5260
'Accept' => 'application/json',
5361
],
@@ -91,4 +99,19 @@ protected function getTokenFields($code)
9199
'grant_type' => 'authorization_code',
92100
]);
93101
}
102+
103+
/**
104+
* Allows compatibility for signed API requests.
105+
*/
106+
protected function generateSignature($endpoint, array $params)
107+
{
108+
$sig = $endpoint;
109+
ksort($params);
110+
foreach ($params as $key => $val) {
111+
$sig .= "|$key=$val";
112+
}
113+
$signing_key = $this->clientSecret;
114+
115+
return hash_hmac('sha256', $sig, $signing_key, false);
116+
}
94117
}

0 commit comments

Comments
 (0)