From e802fc33da214f7bb5057e236ac2e707050bd01b Mon Sep 17 00:00:00 2001 From: eh-steve Date: Mon, 2 Jan 2017 07:38:00 +0000 Subject: [PATCH] Compatibility for signed Instagram API requests (#19) * Compatibility for signed Instagram API requests * StyleCI * StyleCI * StyleCI --- Provider.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Provider.php b/Provider.php index 395b9f3..601480a 100644 --- a/Provider.php +++ b/Provider.php @@ -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', ], @@ -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); + } }