diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e3448a5dc9..ff4564d29c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -364,5 +364,5 @@ Submitting documentation updates, enhancements, designs, or bug fixes. Spelling ### Helping Someone -Searching for Appwrite on Discord, GitHub, or StackOverflow and helping someone else who needs help. You can also help by reaching others how to contribute to Appwrite's repo! +Searching for Appwrite on Discord, GitHub, or StackOverflow and helping someone else who needs help. You can also help by teaching others how to contribute to Appwrite's repo! diff --git a/README.md b/README.md index c87d19e090..035c4dc828 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Getting started with Appwrite is as easy as creating a new project, choosing you * [**Account**](https://appwrite.io/docs/client/account) - Manage current user authentication and account. Track and manage the user sessions, devices, sign-in methods, and security logs. * [**Users**](https://appwrite.io/docs/server/users) - Manage and list all project users when in admin mode. * [**Teams**](https://appwrite.io/docs/client/teams) - Manage and group users in teams. Manage memberships, invites, and user roles within a team. -* [**Database**](https://appwrite.io/docs/client/database) - Manage database collections and documents. Read, create, update, and delete documents and filter lists of documents collections using an advanced filter with graph-like capabilities. +* [**Database**](https://appwrite.io/docs/client/database) - Manage database collections and documents. Read, create, update, and delete documents and filter lists of document collections using advanced filters. * [**Storage**](https://appwrite.io/docs/client/storage) - Manage storage files. Read, create, delete, and preview files. Manipulate the preview of your files to fit your app perfectly. All files are scanned by ClamAV and stored in a secure and encrypted way. * [**Functions**](https://appwrite.io/docs/server/functions) - Customize your Appwrite server by executing your custom code in a secure, isolated environment. You can trigger your code on any Appwrite system event, manually or using a CRON schedule. * [**Locale**](https://appwrite.io/docs/client/locale) - Track your user's location, and manage your app locale-based data. diff --git a/app/config/providers.php b/app/config/providers.php index a377cae6f0..36082433c3 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -163,6 +163,24 @@ return [ // Ordered by ABC. 'beta' => false, 'mock' => false, ], + 'tradeshift' => [ + 'name' => 'Tradeshift', + 'developers' => 'https://developers.tradeshift.com/docs/api', + 'icon' => 'icon-tradeshift', + 'enabled' => true, + 'form' => false, + 'beta' => false, + 'mock' => false, + ], + 'tradeshiftBox' => [ + 'name' => 'Tradeshift Sandbox', + 'developers' => 'https://developers.tradeshift.com/docs/api', + 'icon' => 'icon-tradeshiftbox', + 'enabled' => true, + 'form' => false, + 'beta' => false, + 'mock' => false, + ], 'twitch' => [ 'name' => 'Twitch', 'developers' => 'https://dev.twitch.tv/docs/authentication', @@ -215,6 +233,15 @@ return [ // Ordered by ABC. // 'beta' => false, // 'mock' => false, // ], + 'wordpress' => [ + 'name' => 'WordPress', + 'developers' => 'https://developer.wordpress.com/docs/oauth2/', + 'icon' => 'icon-wordpress', + 'enabled' => true, + 'form' => false, + 'beta' => false, + 'mock' => false + ], // Keep Last 'mock' => [ 'name' => 'Mock', @@ -225,13 +252,4 @@ return [ // Ordered by ABC. 'beta' => false, 'mock' => true, ], - 'wordpress' => [ - 'name' => 'WordPress', - 'developers' => 'https://developer.wordpress.com/docs/oauth2/', - 'icon' => 'icon-wordpress', - 'enabled' => true, - 'form' => false, - 'beta' => false, - 'mock' => false - ] ]; diff --git a/public/images/oauth2/tradeshift.png b/public/images/oauth2/tradeshift.png new file mode 100644 index 0000000000..9a5aaea12f Binary files /dev/null and b/public/images/oauth2/tradeshift.png differ diff --git a/public/images/oauth2/tradeshiftbox.png b/public/images/oauth2/tradeshiftbox.png new file mode 100644 index 0000000000..9a5aaea12f Binary files /dev/null and b/public/images/oauth2/tradeshiftbox.png differ diff --git a/src/Appwrite/Auth/OAuth2/Tradeshift.php b/src/Appwrite/Auth/OAuth2/Tradeshift.php new file mode 100644 index 0000000000..677dd5e044 --- /dev/null +++ b/src/Appwrite/Auth/OAuth2/Tradeshift.php @@ -0,0 +1,155 @@ + self::TRADESHIFT_SANDBOX_API_DOMAIN, + 'live' => self::TRADESHIFT_API_DOMAIN, + ]; + + private $endpoint = [ + 'sandbox' => 'https://' . self::TRADESHIFT_SANDBOX_API_DOMAIN . '/tradeshift/', + 'live' => 'https://' . self::TRADESHIFT_API_DOMAIN . '/tradeshift/', + ]; + + private $resourceEndpoint = [ + 'sandbox' => 'https://' . self::TRADESHIFT_SANDBOX_API_DOMAIN . '/tradeshift/rest/external/', + 'live' => 'https://' . self::TRADESHIFT_API_DOMAIN . '/tradeshift/rest/external/', + ]; + + protected $environment = 'live'; + + /** + * @var array + */ + protected $user = []; + + + protected $scopes = [ + 'openid', + 'offline', + ]; + + /** + * @return string + */ + public function getName(): string + { + return 'tradeshift'; + } + + /** + * @return string + */ + public function getLoginURL(): string + { + $httpQuery = \http_build_query([ + 'response_type' => 'code', + 'client_id' => $this->appID, + 'scope' => \implode(' ', $this->getScopes()), + 'redirect_uri' => \str_replace("localhost", "127.0.0.1", $this->callback), + 'state' => \json_encode($this->state), + ]); + + $url = $this->endpoint[$this->environment] . 'auth/login?' . $httpQuery; + + return $url; + } + + /** + * @param string $code + * + * @return string + */ + public function getAccessToken(string $code): string + { + $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'] ?? ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserID(string $accessToken): string + { + $user = $this->getUser($accessToken); + + return $user['Id'] ?? ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserEmail(string $accessToken): string + { + $user = $this->getUser($accessToken); + + return $user['Username'] ?? ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserName(string $accessToken): string + { + $user = $this->getUser($accessToken); + + $firstName = $user['FirstName'] ?? ''; + $lastName = $user['LastName'] ?? ''; + + return $firstName . ' ' . $lastName; + } + + /** + * @param string $accessToken + * + * @return array + */ + protected function getUser(string $accessToken): array + { + $header = [ + 'Content-Type: application/json', + 'Accept: application/json', + 'Host: ' . urlencode($this->apiDomain[$this->environment]), + 'Authorization: Bearer ' . $accessToken, + ]; + + if (empty($this->user)) { + $response = $this->request( + 'GET', + $this->resourceEndpoint[$this->environment] . 'account/info/user', + $header + ); + $this->user = \json_decode($response, true); + } + + return $this->user; + } +} diff --git a/src/Appwrite/Auth/OAuth2/TradeshiftBox.php b/src/Appwrite/Auth/OAuth2/TradeshiftBox.php new file mode 100644 index 0000000000..6ba3c29f0a --- /dev/null +++ b/src/Appwrite/Auth/OAuth2/TradeshiftBox.php @@ -0,0 +1,18 @@ +