From d9319aa888efc966f48cc47703472afcf7fcf1b1 Mon Sep 17 00:00:00 2001 From: Utkarsh Ahuja Date: Sat, 23 Dec 2023 17:42:34 +0530 Subject: [PATCH 1/7] feat: added zoho oauth metadata --- app/config/providers.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/config/providers.php b/app/config/providers.php index 6ba54f28e4..9d7efc2f1e 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -362,6 +362,16 @@ return [ 'beta' => false, 'mock' => false, ], + 'zoho' => [ + 'name' => 'Zoho', + 'developers' => 'https://zoho.com/accounts/protocol/oauth.html', + 'icon' => 'icon-zoho', + 'enabled' => true, + 'sandbox' => false, + 'form' => false, + 'beta' => false, + 'mock' => false, + ], 'zoom' => [ 'name' => 'Zoom', 'developers' => 'https://marketplace.zoom.us/docs/guides/auth/oauth/', From 09cec17285f5152af42d7a36a6188854c820e7c2 Mon Sep 17 00:00:00 2001 From: Utkarsh Ahuja Date: Fri, 29 Dec 2023 17:43:07 +0000 Subject: [PATCH 2/7] added Zoho OAuth class --- src/Appwrite/Auth/OAuth2/Zoho.php | 164 ++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 src/Appwrite/Auth/OAuth2/Zoho.php diff --git a/src/Appwrite/Auth/OAuth2/Zoho.php b/src/Appwrite/Auth/OAuth2/Zoho.php new file mode 100644 index 0000000000..fefff9a9fb --- /dev/null +++ b/src/Appwrite/Auth/OAuth2/Zoho.php @@ -0,0 +1,164 @@ +authEndpoint . '?' . + \http_build_query([ + 'response_type' => 'code', + 'client_id' => $this->appID, + 'state' => \json_encode($this->state), + 'redirect_uri' => $this->callback, + 'scope' => \implode(' ', $this->getScopes()) + ]); + + return $url; + } + + + /** + * @param string $code + * + * @return array + */ + protected function getTokens(string $code): array + { + if (empty($this->tokens)) { + $this->tokens = \json_decode($this->request( + 'POST', + $this->endpoint . '/oauth/v2/token', + ["Content-Type: application/x-www-form-urlencoded"], + \http_build_query([ + 'grant_type' => 'authorization_code', + "client_id" => $this->appID, + "client_secret" => $this->appSecret, + "redirect_uri" => $this->callback, + 'code' => $code, + 'scope' => \implode(' ', $this->getScopes()), + ]) + ), true); + $this->user = (isset($this->tokens['id_token'])) ? \explode('.', $this->tokens['id_token']) : [0 => '', 1 => '']; + $this->user = (isset($this->user[1])) ? \json_decode(\base64_decode($this->user[1]), true) : []; + } + + return $this->tokens; + } + + + /** + * @param string $refreshToken + * + * @return array + */ + public function refreshTokens(string $refreshToken): array + { + + $this->tokens = \json_decode($this->request( + 'POST', + $this->endpoint . '/oauth/v2/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); + + if (empty($this->tokens['refresh_token'])) { + $this->tokens['refresh_token'] = $refreshToken; + } + + $this->user = (isset($this->tokens['id_token'])) ? \explode('.', $this->tokens['id_token']) : [0 => '', 1 => '']; + $this->user = (isset($this->user[1])) ? \json_decode(\base64_decode($this->user[1]), true) : []; + + return $this->tokens; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserID(string $accessToken): string + { + return $this->user['sub'] ?? ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserEmail(string $accessToken): string + { + return $this->user['email'] ?? ''; + } + + /** + * @param string $accessToken + * + * @return bool + */ + public function isEmailVerified(string $accessToken): bool + { + return $this->user['email_verified'] ?? ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserName(string $accessToken): string + { + return $this->user['name'] ?? ''; + } +} \ No newline at end of file From acebe54e5e0ac576a10b6e983ffbe3011e889d17 Mon Sep 17 00:00:00 2001 From: Utkarsh Ahuja Date: Sun, 31 Dec 2023 19:27:12 +0530 Subject: [PATCH 3/7] fix: email verified false on null --- src/Appwrite/Auth/OAuth2/Zoho.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Auth/OAuth2/Zoho.php b/src/Appwrite/Auth/OAuth2/Zoho.php index fefff9a9fb..245f855958 100644 --- a/src/Appwrite/Auth/OAuth2/Zoho.php +++ b/src/Appwrite/Auth/OAuth2/Zoho.php @@ -149,7 +149,11 @@ class Zoho extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return $this->user['email_verified'] ?? ''; + if ($this->user['email_verified'] ?? false) { + return true; + } + + return false; } /** From 70916ad1aa96a7b5e8ed24bd2ece83df29d4b5b9 Mon Sep 17 00:00:00 2001 From: Utkarsh Ahuja Date: Tue, 2 Jan 2024 10:13:46 +0530 Subject: [PATCH 4/7] fix: removed authEndpoint --- src/Appwrite/Auth/OAuth2/Zoho.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Zoho.php b/src/Appwrite/Auth/OAuth2/Zoho.php index 245f855958..5413bd05da 100644 --- a/src/Appwrite/Auth/OAuth2/Zoho.php +++ b/src/Appwrite/Auth/OAuth2/Zoho.php @@ -14,11 +14,6 @@ class Zoho extends OAuth2 */ private string $endpoint = 'https://accounts.zoho.com'; - /** - * @var string - */ - private string $authEndpoint = 'https://accounts.zoho.com/oauth/v2/auth'; - /** * @var array */ @@ -50,7 +45,7 @@ class Zoho extends OAuth2 */ public function getLoginURL(): string { - $url = $this->authEndpoint . '?' . + $url = $this->endpoint . '/oauth/v2/auth?' . \http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, From c4ab4ca16a70e793902c429f6367dfb13610f9af Mon Sep 17 00:00:00 2001 From: Utkarsh Ahuja <70762626+UtkarshAhuja2003@users.noreply.github.com> Date: Tue, 2 Jan 2024 13:15:07 +0530 Subject: [PATCH 5/7] fix: lint errors --- src/Appwrite/Auth/OAuth2/Zoho.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Auth/OAuth2/Zoho.php b/src/Appwrite/Auth/OAuth2/Zoho.php index 5413bd05da..c2accfbb6d 100644 --- a/src/Appwrite/Auth/OAuth2/Zoho.php +++ b/src/Appwrite/Auth/OAuth2/Zoho.php @@ -160,4 +160,4 @@ class Zoho extends OAuth2 { return $this->user['name'] ?? ''; } -} \ No newline at end of file +} From d18d187a075fb94a3290f1e474d85e08bdefc581 Mon Sep 17 00:00:00 2001 From: Utkarsh Ahuja Date: Wed, 3 Jan 2024 11:20:59 +0530 Subject: [PATCH 6/7] fix: base changed --- app/config/{providers.php => oAuthProviders.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/config/{providers.php => oAuthProviders.php} (100%) diff --git a/app/config/providers.php b/app/config/oAuthProviders.php similarity index 100% rename from app/config/providers.php rename to app/config/oAuthProviders.php From 10dfadbbc70857c0188ad55b39fbbd452e84b53f Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Tue, 2 Jan 2024 22:42:17 +0000 Subject: [PATCH 7/7] Create an enum for Message status --- src/Appwrite/Enum/MessageStatus.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/Appwrite/Enum/MessageStatus.php diff --git a/src/Appwrite/Enum/MessageStatus.php b/src/Appwrite/Enum/MessageStatus.php new file mode 100644 index 0000000000..77ac1a2575 --- /dev/null +++ b/src/Appwrite/Enum/MessageStatus.php @@ -0,0 +1,27 @@ +