From 8f58069b4811c7eae764182e3df806149506dac9 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Tue, 1 Feb 2022 18:13:54 +0100 Subject: [PATCH] Implemented refresh token for all providers --- src/Appwrite/Auth/OAuth2/Amazon.php | 13 ++++++++++++- src/Appwrite/Auth/OAuth2/Apple.php | 16 +++++++++++++++- src/Appwrite/Auth/OAuth2/Bitbucket.php | 13 ++++++++++++- src/Appwrite/Auth/OAuth2/Bitly.php | 13 ++++++++++++- src/Appwrite/Auth/OAuth2/Box.php | 13 ++++++++++++- src/Appwrite/Auth/OAuth2/Discord.php | 12 +++++++++++- src/Appwrite/Auth/OAuth2/Dropbox.php | 13 ++++++++++++- src/Appwrite/Auth/OAuth2/Facebook.php | 12 +++++++++++- src/Appwrite/Auth/OAuth2/Github.php | 13 ++++++++++++- src/Appwrite/Auth/OAuth2/Gitlab.php | 10 +++++++++- src/Appwrite/Auth/OAuth2/Google.php | 10 +++++++++- src/Appwrite/Auth/OAuth2/Linkedin.php | 13 ++++++++++++- src/Appwrite/Auth/OAuth2/Microsoft.php | 13 ++++++++++++- src/Appwrite/Auth/OAuth2/Mock.php | 12 +++++++++++- src/Appwrite/Auth/OAuth2/Notion.php | 11 ++++++++++- src/Appwrite/Auth/OAuth2/Paypal.php | 10 +++++++++- src/Appwrite/Auth/OAuth2/Salesforce.php | 14 +++++++++++++- src/Appwrite/Auth/OAuth2/Slack.php | 11 ++++++++++- src/Appwrite/Auth/OAuth2/Spotify.php | 11 ++++++++++- src/Appwrite/Auth/OAuth2/Stripe.php | 14 ++++++++++++-- src/Appwrite/Auth/OAuth2/Tradeshift.php | 10 +++++++++- src/Appwrite/Auth/OAuth2/Vk.php | 17 ++++++++++++++++- src/Appwrite/Auth/OAuth2/WordPress.php | 12 +++++++++++- src/Appwrite/Auth/OAuth2/Yahoo.php | 15 ++++++++++++++- src/Appwrite/Auth/OAuth2/Yammer.php | 13 ++++++++++++- src/Appwrite/Auth/OAuth2/Yandex.php | 14 +++++++++++++- 26 files changed, 301 insertions(+), 27 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Amazon.php b/src/Appwrite/Auth/OAuth2/Amazon.php index 572047050..c8e809acc 100644 --- a/src/Appwrite/Auth/OAuth2/Amazon.php +++ b/src/Appwrite/Auth/OAuth2/Amazon.php @@ -94,7 +94,18 @@ class Amazon extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8']; + $this->tokens = \json_decode($this->request( + 'POST', + 'https://api.amazon.com/auth/o2/token', + $headers, + \http_build_query([ + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Apple.php b/src/Appwrite/Auth/OAuth2/Apple.php index 51b8c307b..56022c28a 100644 --- a/src/Appwrite/Auth/OAuth2/Apple.php +++ b/src/Appwrite/Auth/OAuth2/Apple.php @@ -92,7 +92,21 @@ class Apple extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = ['Content-Type: application/x-www-form-urlencoded']; + $this->tokens = \json_decode($this->request( + 'POST', + 'https://appleid.apple.com/auth/token', + $headers, + \http_build_query([ + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken, + 'client_id' => $this->appID, + 'client_secret' => $this->getAppSecret(), + ]) + ), true); + + $this->claims = (isset($this->tokens['id_token'])) ? \explode('.', $this->tokens['id_token']) : [0 => '', 1 => '']; + $this->claims = (isset($this->claims[1])) ? \json_decode(\base64_decode($this->claims[1]), true) : []; return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Bitbucket.php b/src/Appwrite/Auth/OAuth2/Bitbucket.php index 6cd31e61f..1e9e9a888 100644 --- a/src/Appwrite/Auth/OAuth2/Bitbucket.php +++ b/src/Appwrite/Auth/OAuth2/Bitbucket.php @@ -78,7 +78,18 @@ class Bitbucket extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = ['Content-Type: application/x-www-form-urlencoded']; + $this->tokens = \json_decode($this->request( + 'POST', + 'https://bitbucket.org/site/oauth2/access_token', + $headers, + \http_build_query([ + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Bitly.php b/src/Appwrite/Auth/OAuth2/Bitly.php index f62379829..1cf727a48 100644 --- a/src/Appwrite/Auth/OAuth2/Bitly.php +++ b/src/Appwrite/Auth/OAuth2/Bitly.php @@ -3,6 +3,7 @@ namespace Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2; +use Utopia\Exception; // Reference Material // https://dev.bitly.com/v4_documentation.html @@ -88,7 +89,17 @@ class Bitly extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'POST', + $this->resourceEndpoint . 'oauth/access_token', + ["Content-Type: application/x-www-form-urlencoded"], + \http_build_query([ + "client_id" => $this->appID, + "client_secret" => $this->appSecret, + "refresh_token" => $refreshToken, + 'grant_type' => 'refresh_token' + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Box.php b/src/Appwrite/Auth/OAuth2/Box.php index d6b57fa33..19cc171ed 100644 --- a/src/Appwrite/Auth/OAuth2/Box.php +++ b/src/Appwrite/Auth/OAuth2/Box.php @@ -95,7 +95,18 @@ class Box extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = ['Content-Type: application/x-www-form-urlencoded']; + $this->tokens = \json_decode($this->request( + 'POST', + $this->endpoint . 'token', + $headers, + \http_build_query([ + "client_id" => $this->appID, + "client_secret" => $this->appSecret, + "refresh_token" => $refreshToken, + "grant_type" => "refresh_token", + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Discord.php b/src/Appwrite/Auth/OAuth2/Discord.php index c3bfc8790..03f752f36 100644 --- a/src/Appwrite/Auth/OAuth2/Discord.php +++ b/src/Appwrite/Auth/OAuth2/Discord.php @@ -90,7 +90,17 @@ class Discord extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'POST', + $this->endpoint . '/oauth2/token', + ['Content-Type: application/x-www-form-urlencoded'], + \http_build_query([ + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Dropbox.php b/src/Appwrite/Auth/OAuth2/Dropbox.php index 9fb3bf733..efff565e0 100644 --- a/src/Appwrite/Auth/OAuth2/Dropbox.php +++ b/src/Appwrite/Auth/OAuth2/Dropbox.php @@ -79,7 +79,18 @@ class Dropbox extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = ['Content-Type: application/x-www-form-urlencoded']; + $this->tokens = \json_decode($this->request( + 'POST', + 'https://api.dropboxapi.com/oauth2/token', + $headers, + \http_build_query([ + 'refresh_token' => $refreshToken, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'grant_type' => 'refresh_token' + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Facebook.php b/src/Appwrite/Auth/OAuth2/Facebook.php index 2a416fbb6..540899616 100644 --- a/src/Appwrite/Auth/OAuth2/Facebook.php +++ b/src/Appwrite/Auth/OAuth2/Facebook.php @@ -3,6 +3,7 @@ namespace Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2; +use Utopia\Exception; class Facebook extends OAuth2 { @@ -78,7 +79,16 @@ class Facebook extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'GET', + 'https://graph.facebook.com/' . $this->version . '/oauth/access_token?' . \http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'client_secret' => $this->appSecret, + 'refresh_token' => $refreshToken, + 'grant_type' => 'refresh_token' + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Github.php b/src/Appwrite/Auth/OAuth2/Github.php index abddc4aaf..0f5703e77 100644 --- a/src/Appwrite/Auth/OAuth2/Github.php +++ b/src/Appwrite/Auth/OAuth2/Github.php @@ -3,6 +3,7 @@ namespace Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2; +use Utopia\Exception; class Github extends OAuth2 { @@ -75,7 +76,17 @@ class Github extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'POST', + 'https://github.com/login/oauth/access_token', + [], + \http_build_query([ + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Gitlab.php b/src/Appwrite/Auth/OAuth2/Gitlab.php index 40052daa6..04b00462b 100644 --- a/src/Appwrite/Auth/OAuth2/Gitlab.php +++ b/src/Appwrite/Auth/OAuth2/Gitlab.php @@ -78,7 +78,15 @@ class Gitlab extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'POST', + 'https://gitlab.com/oauth/token?' . \http_build_query([ + 'refresh_token' => $refreshToken, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'grant_type' => 'refresh_token' + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Google.php b/src/Appwrite/Auth/OAuth2/Google.php index f05df4a8a..bfe437fe4 100644 --- a/src/Appwrite/Auth/OAuth2/Google.php +++ b/src/Appwrite/Auth/OAuth2/Google.php @@ -88,7 +88,15 @@ class Google extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'POST', + 'https://oauth2.googleapis.com/token?' . \http_build_query([ + 'refresh_token' => $refreshToken, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'grant_type' => 'refresh_token' + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Linkedin.php b/src/Appwrite/Auth/OAuth2/Linkedin.php index a719b1448..b1d0775f5 100644 --- a/src/Appwrite/Auth/OAuth2/Linkedin.php +++ b/src/Appwrite/Auth/OAuth2/Linkedin.php @@ -91,7 +91,18 @@ class Linkedin extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'POST', + 'https://www.linkedin.com/oauth/v2/accessToken', + ['Content-Type: application/x-www-form-urlencoded'], + \http_build_query([ + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken, + 'redirect_uri' => $this->callback, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Microsoft.php b/src/Appwrite/Auth/OAuth2/Microsoft.php index 2763ed396..24fb224a5 100644 --- a/src/Appwrite/Auth/OAuth2/Microsoft.php +++ b/src/Appwrite/Auth/OAuth2/Microsoft.php @@ -85,7 +85,18 @@ class Microsoft extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = ['Content-Type: application/x-www-form-urlencoded']; + $this->tokens = \json_decode($this->request( + 'POST', + 'https://login.microsoftonline.com/' . $this->getTenantId() . '/oauth2/v2.0/token', + $headers, + \http_build_query([ + 'refresh_token' => $refreshToken, + 'client_id' => $this->appID, + 'client_secret' => $this->getClientSecret(), + 'grant_type' => 'refresh_token' + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Mock.php b/src/Appwrite/Auth/OAuth2/Mock.php index 1daaeb227..4e1d9a34e 100644 --- a/src/Appwrite/Auth/OAuth2/Mock.php +++ b/src/Appwrite/Auth/OAuth2/Mock.php @@ -3,6 +3,7 @@ namespace Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2; +use Utopia\Exception; class Mock extends OAuth2 { @@ -79,7 +80,16 @@ class Mock extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'GET', + 'http://localhost/' . $this->version . '/mock/tests/general/oauth2/token?' . + \http_build_query([ + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'refresh_token' => $refreshToken, + 'grant_type' => 'refresh_token' + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Notion.php b/src/Appwrite/Auth/OAuth2/Notion.php index f4d00eff3..d63d3285f 100644 --- a/src/Appwrite/Auth/OAuth2/Notion.php +++ b/src/Appwrite/Auth/OAuth2/Notion.php @@ -84,7 +84,16 @@ class Notion extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)]; + $this->tokens = \json_decode($this->request( + 'POST', + $this->endpoint . '/oauth/token', + $headers, + \http_build_query([ + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken, + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Paypal.php b/src/Appwrite/Auth/OAuth2/Paypal.php index 429118e13..87635df8b 100644 --- a/src/Appwrite/Auth/OAuth2/Paypal.php +++ b/src/Appwrite/Auth/OAuth2/Paypal.php @@ -105,7 +105,15 @@ class Paypal extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'POST', + $this->resourceEndpoint[$this->environment] . 'oauth2/token', + ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)], + \http_build_query([ + 'refresh_token' => $refreshToken, + 'grant_type' => 'refresh_token', + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Salesforce.php b/src/Appwrite/Auth/OAuth2/Salesforce.php index 92ed7e2d3..f09c433dc 100644 --- a/src/Appwrite/Auth/OAuth2/Salesforce.php +++ b/src/Appwrite/Auth/OAuth2/Salesforce.php @@ -95,7 +95,19 @@ class Salesforce extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = [ + 'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret), + 'Content-Type: application/x-www-form-urlencoded', + ]; + $this->tokens = \json_decode($this->request( + 'POST', + 'https://login.salesforce.com/services/oauth2/token', + $headers, + \http_build_query([ + 'refresh_token' => $refreshToken, + 'grant_type' => 'refresh_token' + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Slack.php b/src/Appwrite/Auth/OAuth2/Slack.php index bebf8d155..e17d78aa5 100644 --- a/src/Appwrite/Auth/OAuth2/Slack.php +++ b/src/Appwrite/Auth/OAuth2/Slack.php @@ -3,6 +3,7 @@ namespace Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2; +use Utopia\Exception; class Slack extends OAuth2 { @@ -78,7 +79,15 @@ class Slack extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'GET', + 'https://slack.com/api/oauth.access?' . \http_build_query([ + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'refresh_token' => $refreshToken, + 'grant_type' => 'refresh_token' + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Spotify.php b/src/Appwrite/Auth/OAuth2/Spotify.php index e2edaee76..f336ec4bc 100644 --- a/src/Appwrite/Auth/OAuth2/Spotify.php +++ b/src/Appwrite/Auth/OAuth2/Spotify.php @@ -91,7 +91,16 @@ class Spotify extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)]; + $this->tokens = \json_decode($this->request( + 'POST', + $this->endpoint . 'api/token', + $headers, + \http_build_query([ + "refresh_token" => $refreshToken, + "grant_type" => "refresh_token", + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Stripe.php b/src/Appwrite/Auth/OAuth2/Stripe.php index 0d524c870..031c53d44 100644 --- a/src/Appwrite/Auth/OAuth2/Stripe.php +++ b/src/Appwrite/Auth/OAuth2/Stripe.php @@ -3,6 +3,7 @@ namespace Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2; +use Utopia\Exception; class Stripe extends OAuth2 { @@ -34,7 +35,7 @@ class Stripe extends OAuth2 protected $grantType = [ 'authorize' => 'authorization_code', - 'refresh' => 'refresh_token' + 'refresh' => 'refresh_token', ]; /** @@ -90,8 +91,17 @@ class Stripe extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'POST', + 'https://connect.stripe.com/oauth/token', + [], + \http_build_query([ + 'grant_type' => $this->grantType['refresh'], + 'refresh_token' => $refreshToken, + ]) + ), true); + $this->stripeAccountId = $this->tokens['stripe_user_id']; return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Tradeshift.php b/src/Appwrite/Auth/OAuth2/Tradeshift.php index c944b6377..3cb1a51d3 100644 --- a/src/Appwrite/Auth/OAuth2/Tradeshift.php +++ b/src/Appwrite/Auth/OAuth2/Tradeshift.php @@ -100,7 +100,15 @@ class Tradeshift extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'POST', + $this->endpoint[$this->environment] . 'auth/token', + ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)], + \http_build_query([ + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken, + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Vk.php b/src/Appwrite/Auth/OAuth2/Vk.php index 33329628e..7e8b312b6 100644 --- a/src/Appwrite/Auth/OAuth2/Vk.php +++ b/src/Appwrite/Auth/OAuth2/Vk.php @@ -3,6 +3,7 @@ namespace Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2; +use Utopia\Exception; // Reference Material // https://vk.com/dev/first_guide @@ -94,7 +95,21 @@ class Vk extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8']; + $this->tokens = \json_decode($this->request( + 'POST', + 'https://oauth.vk.com/access_token?', + $headers, + \http_build_query([ + 'refresh_token' => $refreshToken, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'grant_type' => 'refresh_token' + ]) + ), true); + + $this->user['email'] = $this->tokens['email']; + $this->user['user_id'] = $this->tokens['user_id']; return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/WordPress.php b/src/Appwrite/Auth/OAuth2/WordPress.php index 4b9286876..6c00d776e 100644 --- a/src/Appwrite/Auth/OAuth2/WordPress.php +++ b/src/Appwrite/Auth/OAuth2/WordPress.php @@ -80,7 +80,17 @@ class WordPress extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $this->tokens = \json_decode($this->request( + 'POST', + 'https://public-api.wordpress.com/oauth2/token', + [], + \http_build_query([ + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Yahoo.php b/src/Appwrite/Auth/OAuth2/Yahoo.php index 12d51d52a..cd3f76798 100644 --- a/src/Appwrite/Auth/OAuth2/Yahoo.php +++ b/src/Appwrite/Auth/OAuth2/Yahoo.php @@ -107,7 +107,20 @@ class Yahoo extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = [ + 'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret), + 'Content-Type: application/x-www-form-urlencoded', + ]; + + $this->tokens = \json_decode($this->request( + 'POST', + $this->endpoint . 'get_token', + $headers, + \http_build_query([ + "refresh_token" => $refreshToken, + "grant_type" => "refresh_token", + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Yammer.php b/src/Appwrite/Auth/OAuth2/Yammer.php index df3863b58..0b1f41027 100644 --- a/src/Appwrite/Auth/OAuth2/Yammer.php +++ b/src/Appwrite/Auth/OAuth2/Yammer.php @@ -78,7 +78,18 @@ class Yammer extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = ['Content-Type: application/x-www-form-urlencoded']; + $this->tokens = \json_decode($this->request( + 'POST', + $this->endpoint . 'access_token?', + $headers, + \http_build_query([ + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'refresh_token' => $refreshToken, + 'grant_type' => 'refresh_token' + ]) + ), true); return $this->tokens; } diff --git a/src/Appwrite/Auth/OAuth2/Yandex.php b/src/Appwrite/Auth/OAuth2/Yandex.php index e54e52f1e..c611e9139 100644 --- a/src/Appwrite/Auth/OAuth2/Yandex.php +++ b/src/Appwrite/Auth/OAuth2/Yandex.php @@ -91,7 +91,19 @@ class Yandex extends OAuth2 */ public function refreshTokens(string $refreshToken):array { - // TODO: Implement (Twitch as example) + $headers = [ + 'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret), + 'Content-Type: application/x-www-form-urlencoded', + ]; + $this->tokens = \json_decode($this->request( + 'POST', + 'https://oauth.yandex.com/token', + $headers, + \http_build_query([ + 'refresh_token' => $refreshToken, + 'grant_type' => 'authorization_code' + ]) + ), true); return $this->tokens; }