diff --git a/app/config/oAuthProviders.php b/app/config/oAuthProviders.php index 6ba54f28e4..9d7efc2f1e 100644 --- a/app/config/oAuthProviders.php +++ b/app/config/oAuthProviders.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/', diff --git a/src/Appwrite/Auth/OAuth2/Zoho.php b/src/Appwrite/Auth/OAuth2/Zoho.php new file mode 100644 index 0000000000..c2accfbb6d --- /dev/null +++ b/src/Appwrite/Auth/OAuth2/Zoho.php @@ -0,0 +1,163 @@ +endpoint . '/oauth/v2/auth?' . + \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 + { + if ($this->user['email_verified'] ?? false) { + return true; + } + + return false; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserName(string $accessToken): string + { + return $this->user['name'] ?? ''; + } +} 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 @@ +