From e9beba4122d3feca195be905e78bf5afbbe1a182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 19 Jun 2022 13:29:52 +0000 Subject: [PATCH 1/2] Simplified, fixed and linted OAuth example --- composer.lock | 206 +++++++++++++------------- docs/tutorials/add-oauth2-provider.md | 107 +++++-------- 2 files changed, 136 insertions(+), 177 deletions(-) diff --git a/composer.lock b/composer.lock index 77a95ecc29..8c2939825c 100644 --- a/composer.lock +++ b/composer.lock @@ -1583,16 +1583,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.6.2", + "version": "3.7.1", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a" + "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a", - "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619", + "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619", "shasum": "" }, "require": { @@ -1635,29 +1635,29 @@ "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "time": "2021-12-12T21:44:58+00:00" + "time": "2022-06-18T07:21:10+00:00" }, { "name": "symfony/deprecation-contracts", - "version": "v2.5.1", + "version": "v3.1.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66" + "reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e8b495ea28c1d97b5e0c121748d6f9b53d075c66", - "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", + "reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=8.1" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.1-dev" }, "thanks": { "name": "symfony/contracts", @@ -1686,7 +1686,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.1" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.1.0" }, "funding": [ { @@ -1702,89 +1702,7 @@ "type": "tidelift" } ], - "time": "2022-01-02T09:53:40+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.26.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", - "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "provide": { - "ext-ctype": "*" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.26-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.26.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-02-25T11:15:52+00:00" }, { "name": "symfony/polyfill-php80", @@ -2905,21 +2823,21 @@ }, { "name": "webmozart/assert", - "version": "1.10.0", + "version": "1.11.0", "source": { "type": "git", "url": "https://github.com/webmozarts/assert.git", - "reference": "6964c76c7804814a842473e0c8fd15bab0f18e25" + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozarts/assert/zipball/6964c76c7804814a842473e0c8fd15bab0f18e25", - "reference": "6964c76c7804814a842473e0c8fd15bab0f18e25", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "symfony/polyfill-ctype": "^1.8" + "ext-ctype": "*", + "php": "^7.2 || ^8.0" }, "conflict": { "phpstan/phpstan": "<0.12.20", @@ -2957,9 +2875,9 @@ ], "support": { "issues": "https://github.com/webmozarts/assert/issues", - "source": "https://github.com/webmozarts/assert/tree/1.10.0" + "source": "https://github.com/webmozarts/assert/tree/1.11.0" }, - "time": "2021-03-09T10:59:23+00:00" + "time": "2022-06-03T18:03:27+00:00" } ], "packages-dev": [ @@ -5086,6 +5004,88 @@ ], "time": "2022-04-18T20:38:04+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.26.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", + "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-ctype": "*" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.26-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.26.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-05-24T11:49:31+00:00" + }, { "name": "symfony/polyfill-mbstring", "version": "v1.26.0", diff --git a/docs/tutorials/add-oauth2-provider.md b/docs/tutorials/add-oauth2-provider.md index f3367d9523..98fbebe639 100644 --- a/docs/tutorials/add-oauth2-provider.md +++ b/docs/tutorials/add-oauth2-provider.md @@ -74,128 +74,86 @@ use Appwrite\Auth\OAuth2; // Reference Material // [DOCS FROM OAUTH PROVIDER] -class [PROVIDER NAME] extends OAuth2 +class Discord extends OAuth2 { - /** - * @var string - */ - private $endpoint = '[ENDPOINT API URL]'; - - /** - * @var array - */ - protected $scopes = [ + private string $endpoint = '[ENDPOINT API URL]'; + protected array $user = []; + protected array $tokens = []; + protected array $scopes = [ // [ARRAY_OF_REQUIRED_SCOPES] ]; - - /** - * @var array - */ - protected $user = []; - - /** - * @var array - */ - protected $tokens = []; - - /** - * @return string - */ + public function getName(): string { return '[PROVIDER NAME]'; } - /** - * @return string - */ public function getLoginURL(): string { $url = $this->endpoint . '[LOGIN_URL_STUFF]'; return $url; } - /** - * @param string $code - * - * @return array - */ protected function getTokens(string $code): array { - if(empty($this->tokens)) { + if (empty($this->tokens)) { // TODO: Fire request to oauth API to generate access_token // Make sure to use '$this->getScopes()' to include all scopes properly - $this->tokens = "[FETCH TOKEN RESPONSE]"; + $this->tokens = ["[FETCH TOKEN RESPONSE]"]; } return $this->tokens; } - - - /** - * @param string $refreshToken - * - * @return array - */ - public function refreshTokens(string $refreshToken):array + + public function refreshTokens(string $refreshToken): array { // TODO: Fire request to oauth API to generate access_token using refresh token - $this->tokens = "[FETCH TOKEN RESPONSE]"; + $this->tokens = ["[FETCH TOKEN RESPONSE]"]; return $this->tokens; } - /** - * @param string $accessToken - * - * @return string - */ public function getUserID(string $accessToken): string { $user = $this->getUser($accessToken); - - // TODO: Pick user ID from $user response + + // TODO: Pick user ID from $user response $userId = "[USER ID]"; - + return $userId; } - /** - * @param string $accessToken - * - * @return string - */ public function getUserEmail(string $accessToken): string { $user = $this->getUser($accessToken); - - // TODO: Pick user email from $user response + + // TODO: Pick user email from $user response $userEmail = "[USER EMAIL]"; - + return $userEmail; } - /** - * @param string $accessToken - * - * @return string - */ + public function isEmailVerified(string $accessToken): bool + { + $user = $this->getUser($accessToken); + + // TODO: Pick user verification status from $user response + $isVerified = "[USER VERIFICATION STATUS]"; + + return $isVerified; + } + public function getUserName(string $accessToken): string { $user = $this->getUser($accessToken); - - // TODO: Pick username from $user response + + // TODO: Pick username from $user response $username = "[USERNAME]"; - + return $username; } - - /** - * @param string $accessToken - * - * @return array - */ - protected function getUser(string $accessToken) + + protected function getUser(string $accessToken): array { if (empty($this->user)) { // TODO: Fire request to oauth API to get information about users @@ -205,6 +163,7 @@ class [PROVIDER NAME] extends OAuth2 return $this->user; } } + ``` > If you copy this template, make sure to replace all placeholders wrapped like `[THIS]` and to implement everything marked as `TODO:`. From eedd7c382b2070c8a65ee1d7deb43b2cd408fd80 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Wed, 22 Jun 2022 10:57:34 +0200 Subject: [PATCH 2/2] Fix leftovers --- docs/tutorials/add-oauth2-provider.md | 4 ++-- docs/tutorials/add-runtime.md | 2 +- docs/tutorials/add-translations.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/add-oauth2-provider.md b/docs/tutorials/add-oauth2-provider.md index 98fbebe639..df2b7d4b2c 100644 --- a/docs/tutorials/add-oauth2-provider.md +++ b/docs/tutorials/add-oauth2-provider.md @@ -74,7 +74,7 @@ use Appwrite\Auth\OAuth2; // Reference Material // [DOCS FROM OAUTH PROVIDER] -class Discord extends OAuth2 +class [PROVIDER NAME] extends OAuth2 { private string $endpoint = '[ENDPOINT API URL]'; protected array $user = []; @@ -192,7 +192,7 @@ First of all, commit the changes with the message `Added XXX OAuth2 Provider` an ## 🤕 Stuck ? -If you need any help with the contribution, feel free to head over to [our discord channel](https://appwrite.io/discord) and we'll be happy to help you out. +If you need any help with the contribution, feel free to head over to [our Discord channel](https://appwrite.io/discord) and we'll be happy to help you out. ## 😉 Need more freedom diff --git a/docs/tutorials/add-runtime.md b/docs/tutorials/add-runtime.md index 8828f27675..ef6eccc421 100644 --- a/docs/tutorials/add-runtime.md +++ b/docs/tutorials/add-runtime.md @@ -254,4 +254,4 @@ First of all, commit the changes with the message `Added XXX Runtime` and push i ## ![face_with_head_bandage](https://github.githubassets.com/images/icons/emoji/unicode/1f915.png) Stuck ? -If you need any help with the contribution, feel free to head over to [our discord channel](https://appwrite.io/discord) and we'll be happy to help you out. +If you need any help with the contribution, feel free to head over to [our Discord channel](https://appwrite.io/discord) and we'll be happy to help you out. diff --git a/docs/tutorials/add-translations.md b/docs/tutorials/add-translations.md index 496bc4a6b1..564ae6526d 100644 --- a/docs/tutorials/add-translations.md +++ b/docs/tutorials/add-translations.md @@ -179,4 +179,4 @@ If you can see countries names translated, everything works, and you are ready f First of all, commit the changes with the message `Added YYY translations` where `YYY` is the translated language and push it. This will publish a new branch to your forked version of Appwrite. If you visit it at `github.com/YOUR_USERNAME/appwrite`, you will see a new alert saying you are ready to submit a pull request. Follow the steps GitHub provides, and at the end, you will have your pull request submitted. ## 🤕 Stuck ? -If you need any help with the contribution, feel free to head over to [our discord channel](https://appwrite.io/discord) and we'll be happy to help you out. +If you need any help with the contribution, feel free to head over to [our Discord channel](https://appwrite.io/discord) and we'll be happy to help you out.