Skip to content

Commit

Permalink
Compatibility for signed Instagram API requests (#19)
Browse files Browse the repository at this point in the history
* Compatibility for signed Instagram API requests

* StyleCI

* StyleCI

* StyleCI
  • Loading branch information
eh-steve authored and faustbrian committed Jan 2, 2017
1 parent 4a220dd commit e802fc3
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ protected function getTokenUrl()
*/
protected function getUserByToken($token)
{
$endpoint = '/users/self';
$query = [
'access_token' => $token,
];
$signature = $this->generateSignature($endpoint, $query);

$query['sig'] = $signature;
$response = $this->getHttpClient()->get(
'https://api.instagram.com/v1/users/self?access_token='.$token, [
'https://api.instagram.com/v1/users/self', [
'query' => $query,
'headers' => [
'Accept' => 'application/json',
],
Expand Down Expand Up @@ -91,4 +99,19 @@ protected function getTokenFields($code)
'grant_type' => 'authorization_code',
]);
}

/**
* Allows compatibility for signed API requests.
*/
protected function generateSignature($endpoint, array $params)
{
$sig = $endpoint;
ksort($params);
foreach ($params as $key => $val) {
$sig .= "|$key=$val";
}
$signing_key = $this->clientSecret;

return hash_hmac('sha256', $sig, $signing_key, false);
}
}

0 comments on commit e802fc3

Please sign in to comment.