From 8ffd82296531a2443201c4419e4b3f2441c645b5 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 28 May 2021 13:53:46 +0530 Subject: [PATCH 1/2] fix: twitch oauth issue --- src/Appwrite/Auth/OAuth2/Twitch.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Twitch.php b/src/Appwrite/Auth/OAuth2/Twitch.php index 463bbf9175..04307a80bd 100644 --- a/src/Appwrite/Auth/OAuth2/Twitch.php +++ b/src/Appwrite/Auth/OAuth2/Twitch.php @@ -24,7 +24,7 @@ class Twitch extends OAuth2 * @var array */ protected $scopes = [ - 'user:read:email', + 'user:read:email', ]; /** @@ -65,9 +65,7 @@ class Twitch extends OAuth2 { $result = \json_decode($this->request( 'POST', - $this->endpoint . 'token', - [], - \http_build_query([ + $this->endpoint . 'token?'. \http_build_query([ "client_id" => $this->appID, "client_secret" => $this->appSecret, "code" => $code, @@ -139,11 +137,15 @@ class Twitch extends OAuth2 protected function getUser(string $accessToken) { if (empty($this->user)) { - $this->user = \json_decode($this->request( + $response = \json_decode($this->request( 'GET', - $this->resourceEndpoint, - ['Authorization: Bearer '.\urlencode($accessToken)] - ), true)['data']['0']; + $this->resourceEndpoint , [ + 'Authorization: Bearer '.\urlencode($accessToken), + 'Client-Id: '. \urlencode($this->appID) + ] + ), true); + + $this->user = $response['data']['0']; } return $this->user; From d39758ba490b8bec931f639c864fba88ae7f0e13 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 28 May 2021 21:50:04 +0530 Subject: [PATCH 2/2] Update src/Appwrite/Auth/OAuth2/Twitch.php Co-authored-by: Eldad A. Fux --- src/Appwrite/Auth/OAuth2/Twitch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Auth/OAuth2/Twitch.php b/src/Appwrite/Auth/OAuth2/Twitch.php index 04307a80bd..9608f9f619 100644 --- a/src/Appwrite/Auth/OAuth2/Twitch.php +++ b/src/Appwrite/Auth/OAuth2/Twitch.php @@ -145,7 +145,7 @@ class Twitch extends OAuth2 ] ), true); - $this->user = $response['data']['0']; + $this->user = $response['data']['0'] ?? []; } return $this->user;