diff --git a/docs/tutorials/add-oauth2-provider.md b/docs/tutorials/add-oauth2-provider.md index 405394da1..43f9f3563 100644 --- a/docs/tutorials/add-oauth2-provider.md +++ b/docs/tutorials/add-oauth2-provider.md @@ -101,9 +101,9 @@ class [PROVIDER NAME] extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { // TODO: Fire request to oauth API to generate access_token $accessToken = "[FETCHED ACCESS TOKEN]"; diff --git a/src/Appwrite/Auth/OAuth2.php b/src/Appwrite/Auth/OAuth2.php index bbae69566..a71bde732 100644 --- a/src/Appwrite/Auth/OAuth2.php +++ b/src/Appwrite/Auth/OAuth2.php @@ -62,9 +62,9 @@ abstract class OAuth2 /** * @param string $code * - * @return mixed + * @return array */ - abstract public function getTokens(string $code):mixed; + abstract public function getTokens(string $code):array; /** * @param $accessToken diff --git a/src/Appwrite/Auth/OAuth2/Amazon.php b/src/Appwrite/Auth/OAuth2/Amazon.php index de5dde8e4..25405795d 100644 --- a/src/Appwrite/Auth/OAuth2/Amazon.php +++ b/src/Appwrite/Auth/OAuth2/Amazon.php @@ -59,31 +59,34 @@ class Amazon extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8']; - $accessToken = $this->request( - 'POST', - 'https://api.amazon.com/auth/o2/token', - $headers, - \http_build_query([ - 'code' => $code, - 'client_id' => $this->appID , - 'client_secret' => $this->appSecret, - 'redirect_uri' => $this->callback , - 'grant_type' => 'authorization_code' - ]) - ); - - $accessToken = \json_decode($accessToken, true); +// $headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8']; +// $accessToken = $this->request( +// 'POST', +// 'https://api.amazon.com/auth/o2/token', +// $headers, +// \http_build_query([ +// 'code' => $code, +// 'client_id' => $this->appID , +// 'client_secret' => $this->appSecret, +// 'redirect_uri' => $this->callback , +// 'grant_type' => 'authorization_code' +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Apple.php b/src/Appwrite/Auth/OAuth2/Apple.php index b0ecbd82f..0fe500243 100644 --- a/src/Appwrite/Auth/OAuth2/Apple.php +++ b/src/Appwrite/Auth/OAuth2/Apple.php @@ -54,34 +54,37 @@ class Apple extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $headers = ['Content-Type: application/x-www-form-urlencoded']; - $accessToken = $this->request( - 'POST', - 'https://appleid.apple.com/auth/token', - $headers, - \http_build_query([ - 'grant_type' => 'authorization_code', - 'code' => $code, - 'client_id' => $this->appID, - 'client_secret' => $this->getAppSecret(), - 'redirect_uri' => $this->callback, - ]) - ); +// $headers = ['Content-Type: application/x-www-form-urlencoded']; +// $accessToken = $this->request( +// 'POST', +// 'https://appleid.apple.com/auth/token', +// $headers, +// \http_build_query([ +// 'grant_type' => 'authorization_code', +// 'code' => $code, +// 'client_id' => $this->appID, +// 'client_secret' => $this->getAppSecret(), +// 'redirect_uri' => $this->callback, +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// $this->claims = (isset($accessToken['id_token'])) ? \explode('.', $accessToken['id_token']) : [0 => '', 1 => '']; +// $this->claims = (isset($this->claims[1])) ? \json_decode(\base64_decode($this->claims[1]), true) : []; +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); - - $this->claims = (isset($accessToken['id_token'])) ? \explode('.', $accessToken['id_token']) : [0 => '', 1 => '']; - $this->claims = (isset($this->claims[1])) ? \json_decode(\base64_decode($this->claims[1]), true) : []; - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Bitbucket.php b/src/Appwrite/Auth/OAuth2/Bitbucket.php index 651aed7f8..e31f038bc 100644 --- a/src/Appwrite/Auth/OAuth2/Bitbucket.php +++ b/src/Appwrite/Auth/OAuth2/Bitbucket.php @@ -43,32 +43,35 @@ class Bitbucket extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - // Required as per Bitbucket Spec. - $headers = ['Content-Type: application/x-www-form-urlencoded']; - - $accessToken = $this->request( - 'POST', - 'https://bitbucket.org/site/oauth2/access_token', - $headers, - \http_build_query([ - 'code' => $code, - 'client_id' => $this->appID, - 'client_secret' => $this->appSecret, - 'grant_type' => 'authorization_code' - ]) - ); +// // Required as per Bitbucket Spec. +// $headers = ['Content-Type: application/x-www-form-urlencoded']; +// +// $accessToken = $this->request( +// 'POST', +// 'https://bitbucket.org/site/oauth2/access_token', +// $headers, +// \http_build_query([ +// 'code' => $code, +// 'client_id' => $this->appID, +// 'client_secret' => $this->appSecret, +// 'grant_type' => 'authorization_code' +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Bitly.php b/src/Appwrite/Auth/OAuth2/Bitly.php index 3da36d503..f098d9c74 100644 --- a/src/Appwrite/Auth/OAuth2/Bitly.php +++ b/src/Appwrite/Auth/OAuth2/Bitly.php @@ -54,31 +54,34 @@ class Bitly extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - $response = $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, - "code" => $code, - "redirect_uri" => $this->callback, - "state" => \json_encode($this->state) - ]) - ); +// $response = $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, +// "code" => $code, +// "redirect_uri" => $this->callback, +// "state" => \json_encode($this->state) +// ]) +// ); +// +// $result = null; +// +// if ($response) { +// \parse_str($response, $result); +// return $result['access_token']; +// } - $result = null; - - if ($response) { - \parse_str($response, $result); - return $result['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Box.php b/src/Appwrite/Auth/OAuth2/Box.php index ad626b633..d63230afb 100644 --- a/src/Appwrite/Auth/OAuth2/Box.php +++ b/src/Appwrite/Auth/OAuth2/Box.php @@ -59,32 +59,35 @@ class Box extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $header = "Content-Type: application/x-www-form-urlencoded"; - $accessToken = $this->request( - 'POST', - $this->endpoint . 'token', - [$header], - \http_build_query([ - "client_id" => $this->appID, - "client_secret" => $this->appSecret, - "code" => $code, - "grant_type" => "authorization_code", - "scope" => \implode(',', $this->getScopes()), - "redirect_uri" => $this->callback - ]) - ); +// $header = "Content-Type: application/x-www-form-urlencoded"; +// $accessToken = $this->request( +// 'POST', +// $this->endpoint . 'token', +// [$header], +// \http_build_query([ +// "client_id" => $this->appID, +// "client_secret" => $this->appSecret, +// "code" => $code, +// "grant_type" => "authorization_code", +// "scope" => \implode(',', $this->getScopes()), +// "redirect_uri" => $this->callback +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (array_key_exists('access_token', $accessToken)) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); - - if (array_key_exists('access_token', $accessToken)) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Discord.php b/src/Appwrite/Auth/OAuth2/Discord.php index f28c2a8dd..7c448bf2b 100644 --- a/src/Appwrite/Auth/OAuth2/Discord.php +++ b/src/Appwrite/Auth/OAuth2/Discord.php @@ -55,31 +55,34 @@ class Discord extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $accessToken = $this->request( - 'POST', - $this->endpoint . '/oauth2/token', - ['Content-Type: application/x-www-form-urlencoded'], - \http_build_query([ - 'grant_type' => 'authorization_code', - 'code' => $code, - 'redirect_uri' => $this->callback, - 'client_id' => $this->appID, - 'client_secret' => $this->appSecret, - 'scope' => \implode(' ', $this->getScopes()) - ]) - ); +// $accessToken = $this->request( +// 'POST', +// $this->endpoint . '/oauth2/token', +// ['Content-Type: application/x-www-form-urlencoded'], +// \http_build_query([ +// 'grant_type' => 'authorization_code', +// 'code' => $code, +// 'redirect_uri' => $this->callback, +// 'client_id' => $this->appID, +// 'client_secret' => $this->appSecret, +// 'scope' => \implode(' ', $this->getScopes()) +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Dropbox.php b/src/Appwrite/Auth/OAuth2/Dropbox.php index 31503d1bc..a8cb1a911 100644 --- a/src/Appwrite/Auth/OAuth2/Dropbox.php +++ b/src/Appwrite/Auth/OAuth2/Dropbox.php @@ -44,31 +44,34 @@ class Dropbox extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $headers = ['Content-Type: application/x-www-form-urlencoded']; - $accessToken = $this->request( - 'POST', - 'https://api.dropboxapi.com/oauth2/token', - $headers, - \http_build_query([ - 'code' => $code, - 'client_id' => $this->appID, - 'client_secret' => $this->appSecret, - 'redirect_uri' => $this->callback, - 'grant_type' => 'authorization_code' - ]) - ); +// $headers = ['Content-Type: application/x-www-form-urlencoded']; +// $accessToken = $this->request( +// 'POST', +// 'https://api.dropboxapi.com/oauth2/token', +// $headers, +// \http_build_query([ +// 'code' => $code, +// 'client_id' => $this->appID, +// 'client_secret' => $this->appSecret, +// 'redirect_uri' => $this->callback, +// 'grant_type' => 'authorization_code' +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Facebook.php b/src/Appwrite/Auth/OAuth2/Facebook.php index 543fbaa1d..4e831c511 100644 --- a/src/Appwrite/Auth/OAuth2/Facebook.php +++ b/src/Appwrite/Auth/OAuth2/Facebook.php @@ -47,27 +47,30 @@ class Facebook extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - $accessToken = $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, - 'code' => $code - ]) - ); +// $accessToken = $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, +// 'code' => $code +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Github.php b/src/Appwrite/Auth/OAuth2/Github.php index 0f86b8910..18886ca27 100644 --- a/src/Appwrite/Auth/OAuth2/Github.php +++ b/src/Appwrite/Auth/OAuth2/Github.php @@ -42,31 +42,34 @@ class Github extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - $accessToken = $this->request( - 'POST', - 'https://github.com/login/oauth/access_token', - [], - \http_build_query([ - 'client_id' => $this->appID, - 'redirect_uri' => $this->callback, - 'client_secret' => $this->appSecret, - 'code' => $code - ]) - ); +// $accessToken = $this->request( +// 'POST', +// 'https://github.com/login/oauth/access_token', +// [], +// \http_build_query([ +// 'client_id' => $this->appID, +// 'redirect_uri' => $this->callback, +// 'client_secret' => $this->appSecret, +// 'code' => $code +// ]) +// ); +// +// $output = []; +// +// \parse_str($accessToken, $output); +// +// if (isset($output['access_token'])) { +// return $output['access_token']; +// } - $output = []; - - \parse_str($accessToken, $output); - - if (isset($output['access_token'])) { - return $output['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Gitlab.php b/src/Appwrite/Auth/OAuth2/Gitlab.php index 369fe0e56..81d98a2ba 100644 --- a/src/Appwrite/Auth/OAuth2/Gitlab.php +++ b/src/Appwrite/Auth/OAuth2/Gitlab.php @@ -46,28 +46,31 @@ class Gitlab extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $accessToken = $this->request( - 'POST', - 'https://gitlab.com/oauth/token?'.\http_build_query([ - 'code' => $code, - 'client_id' => $this->appID, - 'client_secret' => $this->appSecret, - 'redirect_uri' => $this->callback, - 'grant_type' => 'authorization_code' - ]) - ); +// $accessToken = $this->request( +// 'POST', +// 'https://gitlab.com/oauth/token?'.\http_build_query([ +// 'code' => $code, +// 'client_id' => $this->appID, +// 'client_secret' => $this->appSecret, +// 'redirect_uri' => $this->callback, +// 'grant_type' => 'authorization_code' +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Google.php b/src/Appwrite/Auth/OAuth2/Google.php index 506680910..49d1802ac 100644 --- a/src/Appwrite/Auth/OAuth2/Google.php +++ b/src/Appwrite/Auth/OAuth2/Google.php @@ -55,29 +55,32 @@ class Google extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $accessToken = $this->request( - 'POST', - 'https://oauth2.googleapis.com/token?'.\http_build_query([ - 'code' => $code, - 'client_id' => $this->appID, - 'client_secret' => $this->appSecret, - 'redirect_uri' => $this->callback, - 'scope' => null, - 'grant_type' => 'authorization_code' - ]) - ); +// $accessToken = $this->request( +// 'POST', +// 'https://oauth2.googleapis.com/token?'.\http_build_query([ +// 'code' => $code, +// 'client_id' => $this->appID, +// 'client_secret' => $this->appSecret, +// 'redirect_uri' => $this->callback, +// 'scope' => null, +// 'grant_type' => 'authorization_code' +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Linkedin.php b/src/Appwrite/Auth/OAuth2/Linkedin.php index 5f7a76202..657fb8ff5 100644 --- a/src/Appwrite/Auth/OAuth2/Linkedin.php +++ b/src/Appwrite/Auth/OAuth2/Linkedin.php @@ -57,30 +57,33 @@ class Linkedin extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - $accessToken = $this->request( - 'POST', - 'https://www.linkedin.com/oauth/v2/accessToken', - ['Content-Type: application/x-www-form-urlencoded'], - \http_build_query([ - 'grant_type' => 'authorization_code', - 'code' => $code, - 'redirect_uri' => $this->callback, - 'client_id' => $this->appID, - 'client_secret' => $this->appSecret, - ]) - ); +// $accessToken = $this->request( +// 'POST', +// 'https://www.linkedin.com/oauth/v2/accessToken', +// ['Content-Type: application/x-www-form-urlencoded'], +// \http_build_query([ +// 'grant_type' => 'authorization_code', +// 'code' => $code, +// 'redirect_uri' => $this->callback, +// 'client_id' => $this->appID, +// 'client_secret' => $this->appSecret, +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Microsoft.php b/src/Appwrite/Auth/OAuth2/Microsoft.php index c926165e2..595046583 100644 --- a/src/Appwrite/Auth/OAuth2/Microsoft.php +++ b/src/Appwrite/Auth/OAuth2/Microsoft.php @@ -49,33 +49,36 @@ class Microsoft extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $headers = ['Content-Type: application/x-www-form-urlencoded']; +// $headers = ['Content-Type: application/x-www-form-urlencoded']; +// +// $accessToken = $this->request( +// 'POST', +// 'https://login.microsoftonline.com/'.$this->getTenantId().'/oauth2/v2.0/token', +// $headers, +// \http_build_query([ +// 'code' => $code, +// 'client_id' => $this->appID, +// 'client_secret' => $this->getClientSecret(), +// 'redirect_uri' => $this->callback, +// 'scope' => \implode(' ', $this->getScopes()), +// 'grant_type' => 'authorization_code' +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = $this->request( - 'POST', - 'https://login.microsoftonline.com/'.$this->getTenantId().'/oauth2/v2.0/token', - $headers, - \http_build_query([ - 'code' => $code, - 'client_id' => $this->appID, - 'client_secret' => $this->getClientSecret(), - 'redirect_uri' => $this->callback, - 'scope' => \implode(' ', $this->getScopes()), - 'grant_type' => 'authorization_code' - ]) - ); - - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Mock.php b/src/Appwrite/Auth/OAuth2/Mock.php index d7f996293..149691025 100644 --- a/src/Appwrite/Auth/OAuth2/Mock.php +++ b/src/Appwrite/Auth/OAuth2/Mock.php @@ -47,28 +47,31 @@ class Mock extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - $accessToken = $this->request( - 'GET', - 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/token?'. - \http_build_query([ - 'client_id' => $this->appID, - 'redirect_uri' => $this->callback, - 'client_secret' => $this->appSecret, - 'code' => $code - ]) - ); +// $accessToken = $this->request( +// 'GET', +// 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/token?'. +// \http_build_query([ +// 'client_id' => $this->appID, +// 'redirect_uri' => $this->callback, +// 'client_secret' => $this->appSecret, +// 'code' => $code +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); // +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); // - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Notion.php b/src/Appwrite/Auth/OAuth2/Notion.php index 748e7958e..7e7ddd2f3 100644 --- a/src/Appwrite/Auth/OAuth2/Notion.php +++ b/src/Appwrite/Auth/OAuth2/Notion.php @@ -51,32 +51,35 @@ class Notion extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - $headers = [ - "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), +// $headers = [ +// "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), +// ]; +// +// $response = $this->request( +// 'POST', +// $this->endpoint . '/oauth/token', +// $headers, +// \http_build_query([ +// 'grant_type' => 'authorization_code', +// 'redirect_uri' => $this->callback, +// 'code' => $code +// ]) +// ); +// +// $response = \json_decode($response, true); +// +// if (isset($response['access_token'])) { +// return $response['access_token']; +// } + + return [ + 'access' => '', + 'refresh' => '' ]; - - $response = $this->request( - 'POST', - $this->endpoint . '/oauth/token', - $headers, - \http_build_query([ - 'grant_type' => 'authorization_code', - 'redirect_uri' => $this->callback, - 'code' => $code - ]) - ); - - $response = \json_decode($response, true); - - if (isset($response['access_token'])) { - return $response['access_token']; - } - - return ''; } /** diff --git a/src/Appwrite/Auth/OAuth2/Paypal.php b/src/Appwrite/Auth/OAuth2/Paypal.php index 7f431d227..a05f3b35e 100644 --- a/src/Appwrite/Auth/OAuth2/Paypal.php +++ b/src/Appwrite/Auth/OAuth2/Paypal.php @@ -74,29 +74,32 @@ class Paypal extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $accessToken = $this->request( - 'POST', - $this->resourceEndpoint[$this->environment] . 'oauth2/token', - ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)], - \http_build_query([ - 'code' => $code, - 'grant_type' => 'authorization_code', - ]) - ); +// $accessToken = $this->request( +// 'POST', +// $this->resourceEndpoint[$this->environment] . 'oauth2/token', +// ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)], +// \http_build_query([ +// 'code' => $code, +// 'grant_type' => 'authorization_code', +// ]) +// ); +// +// +// $accessToken = \json_decode($accessToken, true); +// +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - - $accessToken = \json_decode($accessToken, true); - - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Salesforce.php b/src/Appwrite/Auth/OAuth2/Salesforce.php index 76256e010..203af8f11 100644 --- a/src/Appwrite/Auth/OAuth2/Salesforce.php +++ b/src/Appwrite/Auth/OAuth2/Salesforce.php @@ -59,32 +59,35 @@ class Salesforce extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $headers = [ - "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), - "Content-Type: application/x-www-form-urlencoded", +// $headers = [ +// "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), +// "Content-Type: application/x-www-form-urlencoded", +// ]; +// +// $accessToken = $this->request( +// 'POST', +// 'https://login.salesforce.com/services/oauth2/token', +// $headers, +// \http_build_query([ +// 'code' => $code, +// 'redirect_uri' => $this->callback , +// 'grant_type' => 'authorization_code' +// ]) +// ); +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } + + return [ + 'access' => '', + 'refresh' => '' ]; - - $accessToken = $this->request( - 'POST', - 'https://login.salesforce.com/services/oauth2/token', - $headers, - \http_build_query([ - 'code' => $code, - 'redirect_uri' => $this->callback , - 'grant_type' => 'authorization_code' - ]) - ); - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; } /** diff --git a/src/Appwrite/Auth/OAuth2/Slack.php b/src/Appwrite/Auth/OAuth2/Slack.php index 20a67456e..bf9647893 100644 --- a/src/Appwrite/Auth/OAuth2/Slack.php +++ b/src/Appwrite/Auth/OAuth2/Slack.php @@ -46,28 +46,31 @@ class Slack extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - // https://api.slack.com/docs/oauth#step_3_-_exchanging_a_verification_code_for_an_access_token - $accessToken = $this->request( - 'GET', - 'https://slack.com/api/oauth.access?'.\http_build_query([ - 'client_id' => $this->appID, - 'client_secret' => $this->appSecret, - 'code' => $code, - 'redirect_uri' => $this->callback - ]) - ); +// // https://api.slack.com/docs/oauth#step_3_-_exchanging_a_verification_code_for_an_access_token +// $accessToken = $this->request( +// 'GET', +// 'https://slack.com/api/oauth.access?'.\http_build_query([ +// 'client_id' => $this->appID, +// 'client_secret' => $this->appSecret, +// 'code' => $code, +// 'redirect_uri' => $this->callback +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); // +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); // - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Spotify.php b/src/Appwrite/Auth/OAuth2/Spotify.php index 7962386b0..f55484330 100644 --- a/src/Appwrite/Auth/OAuth2/Spotify.php +++ b/src/Appwrite/Auth/OAuth2/Spotify.php @@ -58,27 +58,30 @@ class Spotify extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - $header = "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret); - $result = \json_decode($this->request( - 'POST', - $this->endpoint . 'api/token', - [$header], - \http_build_query([ - "code" => $code, - "grant_type" => "authorization_code", - "redirect_uri" => $this->callback - ]) - ), true); +// $header = "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret); +// $result = \json_decode($this->request( +// 'POST', +// $this->endpoint . 'api/token', +// [$header], +// \http_build_query([ +// "code" => $code, +// "grant_type" => "authorization_code", +// "redirect_uri" => $this->callback +// ]) +// ), true); +// +// if (isset($result['access_token'])) { +// return $result['access_token']; +// } - if (isset($result['access_token'])) { - return $result['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Stripe.php b/src/Appwrite/Auth/OAuth2/Stripe.php index ddf028bb4..17b32140b 100644 --- a/src/Appwrite/Auth/OAuth2/Stripe.php +++ b/src/Appwrite/Auth/OAuth2/Stripe.php @@ -57,31 +57,34 @@ class Stripe extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - $response = $this->request( - 'POST', - 'https://connect.stripe.com/oauth/token', - [], - \http_build_query([ - 'grant_type' => $this->grantType['authorize'], - 'code' => $code - ]) - ); +// $response = $this->request( +// 'POST', +// 'https://connect.stripe.com/oauth/token', +// [], +// \http_build_query([ +// 'grant_type' => $this->grantType['authorize'], +// 'code' => $code +// ]) +// ); +// +// $response = \json_decode($response, true); +// +// if (isset($response['stripe_user_id'])) { +// $this->stripeAccountId = $response['stripe_user_id']; +// } +// +// if (isset($response['access_token'])) { +// return $response['access_token']; +// } - $response = \json_decode($response, true); - - if (isset($response['stripe_user_id'])) { - $this->stripeAccountId = $response['stripe_user_id']; - } - - if (isset($response['access_token'])) { - return $response['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Tradeshift.php b/src/Appwrite/Auth/OAuth2/Tradeshift.php index 677dd5e04..e730a41b6 100644 --- a/src/Appwrite/Auth/OAuth2/Tradeshift.php +++ b/src/Appwrite/Auth/OAuth2/Tradeshift.php @@ -69,23 +69,27 @@ class Tradeshift extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $response = $this->request( - 'POST', - $this->endpoint[$this->environment] . 'auth/token', - ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)], - \http_build_query([ - 'grant_type' => 'authorization_code', - 'code' => $code, - ]) - ); +// $response = $this->request( +// 'POST', +// $this->endpoint[$this->environment] . 'auth/token', +// ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)], +// \http_build_query([ +// 'grant_type' => 'authorization_code', +// 'code' => $code, +// ]) +// ); +// +// $accessToken = \json_decode($response, true); +// return $accessToken['access_token'] ?? ''; - $accessToken = \json_decode($response, true); - - return $accessToken['access_token'] ?? ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Twitch.php b/src/Appwrite/Auth/OAuth2/Twitch.php index e6bb6b522..ba48c85ba 100644 --- a/src/Appwrite/Auth/OAuth2/Twitch.php +++ b/src/Appwrite/Auth/OAuth2/Twitch.php @@ -59,9 +59,9 @@ class Twitch extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getTokens(string $code):string + public function getTokens(string $code): array { $result = \json_decode($this->request( 'POST', diff --git a/src/Appwrite/Auth/OAuth2/Vk.php b/src/Appwrite/Auth/OAuth2/Vk.php index bd1d59dad..9ccf3b4d6 100644 --- a/src/Appwrite/Auth/OAuth2/Vk.php +++ b/src/Appwrite/Auth/OAuth2/Vk.php @@ -57,36 +57,40 @@ class Vk extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8']; - $accessToken = $this->request( - 'POST', - 'https://oauth.vk.com/access_token?', - $headers, - \http_build_query([ - 'code' => $code, - 'client_id' => $this->appID, - 'client_secret' => $this->appSecret, - 'redirect_uri' => $this->callback - ]) - ); - $accessToken = \json_decode($accessToken, true); +// $headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8']; +// $accessToken = $this->request( +// 'POST', +// 'https://oauth.vk.com/access_token?', +// $headers, +// \http_build_query([ +// 'code' => $code, +// 'client_id' => $this->appID, +// 'client_secret' => $this->appSecret, +// 'redirect_uri' => $this->callback +// ]) +// ); +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['email'])) { +// $this->user['email'] = $accessToken['email']; +// } +// +// if (isset($accessToken['user_id'])) { +// $this->user['user_id'] = $accessToken['user_id']; +// } +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - if (isset($accessToken['email'])) { - $this->user['email'] = $accessToken['email']; - } - - if (isset($accessToken['user_id'])) { - $this->user['user_id'] = $accessToken['user_id']; - } - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/WordPress.php b/src/Appwrite/Auth/OAuth2/WordPress.php index a83953405..3c012aa5b 100644 --- a/src/Appwrite/Auth/OAuth2/WordPress.php +++ b/src/Appwrite/Auth/OAuth2/WordPress.php @@ -46,30 +46,33 @@ class WordPress extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - $accessToken = $this->request( - 'POST', - 'https://public-api.wordpress.com/oauth2/token', - [], - \http_build_query([ - 'client_id' => $this->appID, - 'redirect_uri' => $this->callback, - 'client_secret' => $this->appSecret, - 'grant_type' => 'authorization_code', - 'code' => $code - ]) - ); +// $accessToken = $this->request( +// 'POST', +// 'https://public-api.wordpress.com/oauth2/token', +// [], +// \http_build_query([ +// 'client_id' => $this->appID, +// 'redirect_uri' => $this->callback, +// 'client_secret' => $this->appSecret, +// 'grant_type' => 'authorization_code', +// 'code' => $code +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Yahoo.php b/src/Appwrite/Auth/OAuth2/Yahoo.php index 1702e6968..0abe1eb1d 100644 --- a/src/Appwrite/Auth/OAuth2/Yahoo.php +++ b/src/Appwrite/Auth/OAuth2/Yahoo.php @@ -70,31 +70,34 @@ class Yahoo extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code):string + public function getTokens(string $code): array { - $header = [ - "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), - "Content-Type: application/x-www-form-urlencoded", +// $header = [ +// "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), +// "Content-Type: application/x-www-form-urlencoded", +// ]; +// +// $result = \json_decode($this->request( +// 'POST', +// $this->endpoint . 'get_token', +// $header, +// \http_build_query([ +// "code" => $code, +// "grant_type" => "authorization_code", +// "redirect_uri" => $this->callback +// ]) +// ), true); +// +// if (isset($result['access_token'])) { +// return $result['access_token']; +// } + + return [ + 'access' => '', + 'refresh' => '' ]; - - $result = \json_decode($this->request( - 'POST', - $this->endpoint . 'get_token', - $header, - \http_build_query([ - "code" => $code, - "grant_type" => "authorization_code", - "redirect_uri" => $this->callback - ]) - ), true); - - if (isset($result['access_token'])) { - return $result['access_token']; - } - - return ''; } /** diff --git a/src/Appwrite/Auth/OAuth2/Yammer.php b/src/Appwrite/Auth/OAuth2/Yammer.php index 832d886ee..3e26e7cfe 100644 --- a/src/Appwrite/Auth/OAuth2/Yammer.php +++ b/src/Appwrite/Auth/OAuth2/Yammer.php @@ -44,31 +44,34 @@ class Yammer extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $headers = ['Content-Type: application/x-www-form-urlencoded']; +// $headers = ['Content-Type: application/x-www-form-urlencoded']; +// +// $accessToken = $this->request( +// 'POST', +// $this->endpoint . 'access_token?', +// $headers, +// \http_build_query([ +// 'client_id' => $this->appID, +// 'client_secret' => $this->appSecret, +// 'code' => $code, +// 'grant_type' => 'authorization_code' +// ]) +// ); +// +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token']['token'])) { +// return $accessToken['access_token']['token']; +// } - $accessToken = $this->request( - 'POST', - $this->endpoint . 'access_token?', - $headers, - \http_build_query([ - 'client_id' => $this->appID, - 'client_secret' => $this->appSecret, - 'code' => $code, - 'grant_type' => 'authorization_code' - ]) - ); - - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token']['token'])) { - return $accessToken['access_token']['token']; - } - - return ''; + return [ + 'access' => '', + 'refresh' => '' + ]; } /** diff --git a/src/Appwrite/Auth/OAuth2/Yandex.php b/src/Appwrite/Auth/OAuth2/Yandex.php index e6b94677d..ecb904181 100644 --- a/src/Appwrite/Auth/OAuth2/Yandex.php +++ b/src/Appwrite/Auth/OAuth2/Yandex.php @@ -56,31 +56,34 @@ class Yandex extends OAuth2 /** * @param string $code * - * @return string + * @return array */ - public function getAccessToken(string $code): string + public function getTokens(string $code): array { - $headers = [ - "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), - "Content-Type: application/x-www-form-urlencoded", +// $headers = [ +// "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), +// "Content-Type: application/x-www-form-urlencoded", +// ]; +// +// $accessToken = $this->request( +// 'POST', +// 'https://oauth.yandex.com/token', +// $headers, +// \http_build_query([ +// 'code' => $code, +// 'grant_type' => 'authorization_code' +// ]) +// ); +// $accessToken = \json_decode($accessToken, true); +// +// if (isset($accessToken['access_token'])) { +// return $accessToken['access_token']; +// } + + return [ + 'access' => '', + 'refresh' => '' ]; - - $accessToken = $this->request( - 'POST', - 'https://oauth.yandex.com/token', - $headers, - \http_build_query([ - 'code' => $code, - 'grant_type' => 'authorization_code' - ]) - ); - $accessToken = \json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; } /**