From a8a61701b29c0ffdedcd3374e470ed9386afd447 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Sat, 5 Feb 2022 16:25:47 +0100 Subject: [PATCH 1/3] Fixed GitHub response parsing --- src/Appwrite/Auth/OAuth2/Github.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Github.php b/src/Appwrite/Auth/OAuth2/Github.php index 22ffbe937..ceda2a474 100644 --- a/src/Appwrite/Auth/OAuth2/Github.php +++ b/src/Appwrite/Auth/OAuth2/Github.php @@ -53,7 +53,7 @@ class Github extends OAuth2 protected function getTokens(string $code): array { if(empty($this->tokens)) { - $this->tokens = \json_decode($this->request( + $response = $this->request( 'POST', 'https://github.com/login/oauth/access_token', [], @@ -63,7 +63,11 @@ class Github extends OAuth2 'client_secret' => $this->appSecret, 'code' => $code ]) - ), true); + ); + + $output = []; + \parse_str($response, $output); + $this->tokens = $output; } return $this->tokens; From ecb1d21953f32e163e8a67aa99d7bddb5baaeeb6 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Sat, 5 Feb 2022 16:38:08 +0100 Subject: [PATCH 2/3] Fixed Bitly response parsing --- src/Appwrite/Auth/OAuth2/Bitly.php | 18 +++++++++++++----- src/Appwrite/Auth/OAuth2/Github.php | 8 ++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Bitly.php b/src/Appwrite/Auth/OAuth2/Bitly.php index 4b7e525a7..fb1cb57e1 100644 --- a/src/Appwrite/Auth/OAuth2/Bitly.php +++ b/src/Appwrite/Auth/OAuth2/Bitly.php @@ -65,7 +65,7 @@ class Bitly extends OAuth2 protected function getTokens(string $code): array { if(empty($this->tokens)) { - $this->tokens = \json_decode($this->request( + $response = $this->request( 'POST', $this->resourceEndpoint . 'oauth/access_token', ["Content-Type: application/x-www-form-urlencoded"], @@ -76,8 +76,12 @@ class Bitly extends OAuth2 "redirect_uri" => $this->callback, "state" => \json_encode($this->state) ]) - ), true); - } + ); + + $output = []; + \parse_str($response, $output); + $this->tokens = $output; + } return $this->tokens; } @@ -89,7 +93,7 @@ class Bitly extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - $this->tokens = \json_decode($this->request( + $response = $this->request( 'POST', $this->resourceEndpoint . 'oauth/access_token', ["Content-Type: application/x-www-form-urlencoded"], @@ -99,7 +103,11 @@ class Bitly extends OAuth2 "refresh_token" => $refreshToken, 'grant_type' => 'refresh_token' ]) - ), true); + ); + + $output = []; + \parse_str($response, $output); + $this->tokens = $output; if(empty($this->tokens['refresh_token'])) { $this->tokens['refresh_token'] = $refreshToken; diff --git a/src/Appwrite/Auth/OAuth2/Github.php b/src/Appwrite/Auth/OAuth2/Github.php index ceda2a474..dddd4a518 100644 --- a/src/Appwrite/Auth/OAuth2/Github.php +++ b/src/Appwrite/Auth/OAuth2/Github.php @@ -80,7 +80,7 @@ class Github extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - $this->tokens = \json_decode($this->request( + $response = $this->request( 'POST', 'https://github.com/login/oauth/access_token', [], @@ -90,7 +90,11 @@ class Github extends OAuth2 'grant_type' => 'refresh_token', 'refresh_token' => $refreshToken ]) - ), true); + ); + + $output = []; + \parse_str($response, $output); + $this->tokens = $output; if(empty($this->tokens['refresh_token'])) { $this->tokens['refresh_token'] = $refreshToken; From 9d24a1532b4bd12d803b27ecddf124d01968558f Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Sat, 5 Feb 2022 16:49:34 +0100 Subject: [PATCH 3/3] Cleanup --- src/Appwrite/Auth/OAuth2/Bitly.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Bitly.php b/src/Appwrite/Auth/OAuth2/Bitly.php index fb1cb57e1..02a21dc29 100644 --- a/src/Appwrite/Auth/OAuth2/Bitly.php +++ b/src/Appwrite/Auth/OAuth2/Bitly.php @@ -78,10 +78,10 @@ class Bitly extends OAuth2 ]) ); - $output = []; - \parse_str($response, $output); - $this->tokens = $output; - } + $output = []; + \parse_str($response, $output); + $this->tokens = $output; + } return $this->tokens; }