diff --git a/src/Appwrite/Auth/OAuth2/Amazon.php b/src/Appwrite/Auth/OAuth2/Amazon.php index 5720470509..c8e809acce 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 51b8c307bb..56022c28ae 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 6cd31e61f7..1e9e9a8880 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 f62379829d..1cf727a481 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 d6b57fa333..19cc171ed8 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 c3bfc87909..03f752f369 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 9fb3bf733a..efff565e0c 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 2a416fbb68..540899616d 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 abddc4aafd..0f5703e774 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 40052daa61..04b00462b8 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 f05df4a8a7..bfe437fe42 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 a719b14486..b1d0775f56 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 2763ed3969..24fb224a52 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 1daaeb2279..4e1d9a34e5 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 f4d00eff3f..d63d3285f5 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 429118e13b..87635df8b9 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 92ed7e2d3c..f09c433dc6 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 bebf8d1550..e17d78aa56 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 e2edaee76d..f336ec4bca 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 0d524c870e..031c53d443 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 c944b63772..3cb1a51d3a 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 33329628e8..7e8b312b67 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 4b92868761..6c00d776e3 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 12d51d52a7..cd3f767989 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 df3863b58b..0b1f41027c 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 e54e52f1e9..c611e9139a 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; }