From e717a3caf0fe5994affaf8d61f55420b931e05fb Mon Sep 17 00:00:00 2001 From: slerdev <82650558+slerdev@users.noreply.github.com> Date: Mon, 16 Aug 2021 13:22:52 +0200 Subject: [PATCH 1/4] Update Twitch API --- src/OAuth2/Provider/Twitch.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/OAuth2/Provider/Twitch.php b/src/OAuth2/Provider/Twitch.php index 2ea72b55d..db6b05449 100644 --- a/src/OAuth2/Provider/Twitch.php +++ b/src/OAuth2/Provider/Twitch.php @@ -20,7 +20,7 @@ class Twitch extends \SocialConnect\OAuth2\AbstractProvider */ public function getBaseUri() { - return 'https://api.twitch.tv/kraken/'; + return 'https://api.twitch.tv/helix/'; } /** @@ -28,7 +28,7 @@ public function getBaseUri() */ public function getAuthorizeUri() { - return 'https://api.twitch.tv/kraken/oauth2/authorize'; + return 'https://id.twitch.tv/oauth2/authorize'; } /** @@ -36,7 +36,7 @@ public function getAuthorizeUri() */ public function getRequestTokenUri() { - return 'https://api.twitch.tv/kraken/oauth2/token'; + return 'https://id.twitch.tv/oauth2/token'; } /** @@ -62,7 +62,9 @@ public function getScopeInline() public function prepareRequest(string $method, string $uri, array &$headers, array &$query, AccessTokenInterface $accessToken = null): void { if ($accessToken) { - $query['oauth_token'] = $accessToken->getToken(); + $headers['Authorization'] = "Bearer {$accessToken->getToken()}"; + $headers['Client-Id'] = $this->consumer->getKey(); + } } @@ -71,14 +73,14 @@ public function prepareRequest(string $method, string $uri, array &$headers, arr */ public function getIdentity(AccessTokenInterface $accessToken) { - $response = $this->request('GET', 'user', [], $accessToken); + $response = $this->request('GET', 'users', [], $accessToken); $hydrator = new ArrayHydrator([ - '_id' => 'id', + 'id' => 'id', 'display_name' => 'fullname', // Custom Capitalized Users name - 'name' => 'username', + 'email' => 'email' ]); - return $hydrator->hydrate(new User(), $response); + return $hydrator->hydrate(new User(), $response["data"][0]); } } From bdfc48092a5e0c86f872aea508ed23b646511e35 Mon Sep 17 00:00:00 2001 From: slerdev <82650558+slerdev@users.noreply.github.com> Date: Mon, 16 Aug 2021 21:56:47 +0200 Subject: [PATCH 2/4] Update src/OAuth2/Provider/Twitch.php Co-authored-by: ADmad --- src/OAuth2/Provider/Twitch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OAuth2/Provider/Twitch.php b/src/OAuth2/Provider/Twitch.php index db6b05449..e1a28f327 100644 --- a/src/OAuth2/Provider/Twitch.php +++ b/src/OAuth2/Provider/Twitch.php @@ -81,6 +81,6 @@ public function getIdentity(AccessTokenInterface $accessToken) 'email' => 'email' ]); - return $hydrator->hydrate(new User(), $response["data"][0]); + return $hydrator->hydrate(new User(), $response['data'][0]); } } From 0728145633a7c39b7fd7efd9158f7bebe10bbd63 Mon Sep 17 00:00:00 2001 From: slerdev <82650558+slerdev@users.noreply.github.com> Date: Mon, 16 Aug 2021 22:01:26 +0200 Subject: [PATCH 3/4] Map more Twitch fields --- src/OAuth2/Provider/Twitch.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OAuth2/Provider/Twitch.php b/src/OAuth2/Provider/Twitch.php index e1a28f327..8394b1c33 100644 --- a/src/OAuth2/Provider/Twitch.php +++ b/src/OAuth2/Provider/Twitch.php @@ -78,6 +78,8 @@ public function getIdentity(AccessTokenInterface $accessToken) $hydrator = new ArrayHydrator([ 'id' => 'id', 'display_name' => 'fullname', // Custom Capitalized Users name + 'login' => 'username', + 'profile_image_url' => 'pictureURL', 'email' => 'email' ]); From ba1110d717451728a64397983ab29335f13ea2fa Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 17 Aug 2021 10:56:36 +0530 Subject: [PATCH 4/4] Fix CS error --- src/OAuth2/Provider/Twitch.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OAuth2/Provider/Twitch.php b/src/OAuth2/Provider/Twitch.php index 8394b1c33..6712f4bba 100644 --- a/src/OAuth2/Provider/Twitch.php +++ b/src/OAuth2/Provider/Twitch.php @@ -64,7 +64,6 @@ public function prepareRequest(string $method, string $uri, array &$headers, arr if ($accessToken) { $headers['Authorization'] = "Bearer {$accessToken->getToken()}"; $headers['Client-Id'] = $this->consumer->getKey(); - } }