From efa4efd84885ba1953682f01d67ced92b4b69cb4 Mon Sep 17 00:00:00 2001 From: Geidson Benicio Coelho Date: Tue, 1 Feb 2022 18:55:51 -0300 Subject: [PATCH 1/6] Versao do pacote para laravel 8 e 10 --- composer.json | 4 +- src/Console/ClientCommand.php | 118 +++++++++++++++++++++++++ src/MongodbPassportServiceProvider.php | 11 ++- 3 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 src/Console/ClientCommand.php diff --git a/composer.json b/composer.json index fb36078..ed6e637 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ "require": { "php": ">=7.1", "illuminate/support": "^5.5 || ^6.0", - "jenssegers/mongodb": "3.3.* || 3.4.* || 3.5.* || 3.6.*", - "laravel/passport": "6.0.* || 7.0.* || 7.4.* || 7.5.* || ^8.0 || ^9.0" + "jenssegers/mongodb": "3.3.* || 3.4.* || 3.5.* || 3.6.* || 3.8.*", + "laravel/passport": "6.0.* || 7.0.* || 7.4.* || 7.5.* || ^8.0 || ^9.0 || ^10" }, "autoload": { "psr-4": { diff --git a/src/Console/ClientCommand.php b/src/Console/ClientCommand.php new file mode 100644 index 0000000..697f838 --- /dev/null +++ b/src/Console/ClientCommand.php @@ -0,0 +1,118 @@ +option('name') ?: $this->ask( + 'What should we name the personal access client?', + config('app.name').' Personal Access Client' + ); + + $client = $clients->createPersonalAccessClient( + null, $name, 'http://localhost' + ); + + $this->info('Personal access client created successfully.'); + + $this->patchedOutputClientDetails($client); + } + + /** + * Create a new password grant client. + * + * @param \Laravel\Passport\ClientRepository $clients + * @return void + */ + protected function createPasswordClient(ClientRepository $clients) + { + $name = $this->option('name') ?: $this->ask( + 'What should we name the password grant client?', + config('app.name').' Password Grant Client' + ); + + $client = $clients->createPasswordGrantClient( + null, $name, 'http://localhost' + ); + + $this->info('Password grant client created successfully.'); + + $this->patchedOutputClientDetails($client); + } + + /** + * Create a client credentials grant client. + * + * @param \Laravel\Passport\ClientRepository $clients + * @return void + */ + protected function createClientCredentialsClient(ClientRepository $clients) + { + $name = $this->option('name') ?: $this->ask( + 'What should we name the client?', + config('app.name').' ClientCredentials Grant Client' + ); + + $client = $clients->create( + null, $name, '' + ); + + $this->info('New client created successfully.'); + + $this->patchedOutputClientDetails($client); + } + + /** + * Create a authorization code client. + * + * @param \Laravel\Passport\ClientRepository $clients + * @return void + */ + protected function createAuthCodeClient(ClientRepository $clients) + { + $userId = $this->option('user_id') ?: $this->ask( + 'Which user ID should the client be assigned to?' + ); + + $name = $this->option('name') ?: $this->ask( + 'What should we name the client?' + ); + + $redirect = $this->option('redirect_uri') ?: $this->ask( + 'Where should we redirect the request after authorization?', + url('/auth/callback') + ); + + $client = $clients->create( + $userId, $name, $redirect, false, false, ! $this->option('public') + ); + + $this->info('New client created successfully.'); + + $this->patchedOutputClientDetails($client); + } + + /** + * Output the client's ID and secret key. + * + * @param \Laravel\Passport\Client $client + * @return void + */ + protected function patchedOutputClientDetails(Client $client) + { + $this->line('Client ID: '.$client->id); + $this->line('Client secret: '.$client->secret); + } +} diff --git a/src/MongodbPassportServiceProvider.php b/src/MongodbPassportServiceProvider.php index 37723a3..947d886 100644 --- a/src/MongodbPassportServiceProvider.php +++ b/src/MongodbPassportServiceProvider.php @@ -4,19 +4,20 @@ use Illuminate\Support\ServiceProvider; use DesignMyNight\Mongodb\Passport\AuthCode; +use DesignMyNight\Mongodb\Console\ClientCommand; use DesignMyNight\Mongodb\Passport\Bridge\RefreshTokenRepository; use DesignMyNight\Mongodb\Passport\Client; use DesignMyNight\Mongodb\Passport\PersonalAccessClient; -use DesignMyNight\Mongodb\Passport\RefreshToken; use DesignMyNight\Mongodb\Passport\Token; use Laravel\Passport\Bridge\RefreshTokenRepository as PassportRefreshTokenRepository; +use Laravel\Passport\Console\ClientCommand as PassportClientCommand; use Laravel\Passport\Passport; class MongodbPassportServiceProvider extends ServiceProvider { /** - * @return void - */ + * @return void + */ public function register() { Passport::useAuthCodeModel(AuthCode::class); @@ -27,5 +28,9 @@ public function register() $this->app->bind(PassportRefreshTokenRepository::class, function () { return $this->app->make(RefreshTokenRepository::class); }); + + $this->app->extend(PassportClientCommand::class, function () { + return new ClientCommand(); + }); } } From 85e75f5c49a69ddce553427b2a627ed9f815c85d Mon Sep 17 00:00:00 2001 From: Geidson Benicio Coelho Date: Wed, 2 Feb 2022 11:13:32 -0300 Subject: [PATCH 2/6] Change project name in composer json --- composer.json | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index ed6e637..4a03eb7 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { - "name": "designmynight/laravel-mongodb-passport", + "name": "sysvale/laravel-mongodb-passport", "description": "A package to allow laravel/passport use with jenssegers/laravel-mongodb", - "homepage": "https://github.com/designmynight/laravel-mongodb-passport", + "homepage": "https://github.com/Sysvale/laravel-mongodb-passport", "license": "MIT", "keywords": [ "laravel", @@ -10,7 +10,7 @@ "laravel-passport", "mongodb", "passport", - "designmynight" + "sysvale" ], "require": { "php": ">=7.1", @@ -20,7 +20,7 @@ }, "autoload": { "psr-4": { - "DesignMyNight\\Mongodb\\": "src" + "Sysvale\\Mongodb\\": "src" } }, "authors": [ @@ -28,12 +28,16 @@ "name": "DesignMyNight", "email": "support@designmynight.com", "role": "Support" + }, + { + "name": "Geidson", + "email": "geidson@sysvale.com" } ], "extra": { "laravel": { "providers": [ - "DesignMyNight\\Mongodb\\MongodbPassportServiceProvider" + "Sysvale\\Mongodb\\MongodbPassportServiceProvider" ] } } From 8fbba9db410c23d2eaf77e5754e18c9c5263f70f Mon Sep 17 00:00:00 2001 From: Geidson Benicio Coelho Date: Wed, 2 Feb 2022 11:27:41 -0300 Subject: [PATCH 3/6] update namespace --- README.md | 12 ++++++------ src/Auth/User.php | 2 +- src/Console/ClientCommand.php | 4 ++-- src/MongodbPassportServiceProvider.php | 14 +++++++------- src/Passport/AuthCode.php | 2 +- src/Passport/Bridge/RefreshToken.php | 4 ++-- src/Passport/Bridge/RefreshTokenRepository.php | 2 +- src/Passport/Client.php | 4 ++-- src/Passport/PersonalAccessClient.php | 2 +- src/Passport/PersonalAccessTokenFactory.php | 2 +- src/Passport/RefreshToken.php | 4 ++-- src/Passport/Token.php | 2 +- 12 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index e333236..f24dff4 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ Installation Installation using composer: ```sh -composer require designmynight/laravel-mongodb-passport +composer require sysvale/laravel-mongodb-passport ``` -You need to have your `App\User` class extend `DesignMyNight\Mongodb\Auth\User.php` instead of the default `Illuminate\Foundation\Auth\User`. This user class extends larvel-mongodb eloquent user as well as adding all the standard and required authentication and laravel passport traits. +You need to have your `App\User` class extend `Sysvale\Mongodb\Auth\User.php` instead of the default `Illuminate\Foundation\Auth\User`. This user class extends larvel-mongodb eloquent user as well as adding all the standard and required authentication and laravel passport traits. ```php register(DesignMyNight\Mongodb\MongodbPassportServiceProvider::class); +$app->register(Sysvale\Mongodb\MongodbPassportServiceProvider::class); ``` The service provider will overide the default laravel passport models in order to use mongodb's implementation of eloquent. There is no need to register any additional classes or add any additional configuration other than those outlined in [Laravel Passport](https://github.com/laravel/passport) and [MongoDB](https://github.com/jenssegers/laravel-mongodb). diff --git a/src/Auth/User.php b/src/Auth/User.php index 5970e0a..cda5168 100644 --- a/src/Auth/User.php +++ b/src/Auth/User.php @@ -1,6 +1,6 @@ Date: Wed, 2 Feb 2022 11:54:21 -0300 Subject: [PATCH 4/6] Change project name in composer json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4a03eb7..982a715 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "require": { "php": ">=7.1", - "illuminate/support": "^5.5 || ^6.0", + "illuminate/support": "^5.5 || ^6.0 || ^7.0 || ^8.0", "jenssegers/mongodb": "3.3.* || 3.4.* || 3.5.* || 3.6.* || 3.8.*", "laravel/passport": "6.0.* || 7.0.* || 7.4.* || 7.5.* || ^8.0 || ^9.0 || ^10" }, From 0359d1b6e0de43cc3fb538cd0d58e841302c32ad Mon Sep 17 00:00:00 2001 From: Geidson Benicio Coelho Date: Thu, 31 Mar 2022 10:20:38 -0300 Subject: [PATCH 5/6] Sobescreve classe TokenRepository para resolver problema com tipos de classes --- src/MongodbPassportServiceProvider.php | 4 ++++ src/Passport/TokenRepository.php | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/Passport/TokenRepository.php diff --git a/src/MongodbPassportServiceProvider.php b/src/MongodbPassportServiceProvider.php index 189ef55..0890ce5 100644 --- a/src/MongodbPassportServiceProvider.php +++ b/src/MongodbPassportServiceProvider.php @@ -32,5 +32,9 @@ public function register() $this->app->extend(PassportClientCommand::class, function () { return new ClientCommand(); }); + + $this->app->bind(PassportTokenRepository::class, function () { + return $this->app->make(TokenRepository::class); + }); } } diff --git a/src/Passport/TokenRepository.php b/src/Passport/TokenRepository.php new file mode 100644 index 0000000..21fd360 --- /dev/null +++ b/src/Passport/TokenRepository.php @@ -0,0 +1,21 @@ +save(); + } + +} From cfd5a2308c18acfcc69461f41f84022fd0ccc5cc Mon Sep 17 00:00:00 2001 From: Geidson Benicio Coelho Date: Thu, 31 Mar 2022 10:31:17 -0300 Subject: [PATCH 6/6] Sobescreve classe TokenRepository para resolver problema com tipos de classes --- src/MongodbPassportServiceProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/MongodbPassportServiceProvider.php b/src/MongodbPassportServiceProvider.php index 0890ce5..fb2c6a5 100644 --- a/src/MongodbPassportServiceProvider.php +++ b/src/MongodbPassportServiceProvider.php @@ -12,6 +12,8 @@ use Laravel\Passport\Bridge\RefreshTokenRepository as PassportRefreshTokenRepository; use Laravel\Passport\Console\ClientCommand as PassportClientCommand; use Laravel\Passport\Passport; +use Laravel\Passport\TokenRepository as PassportTokenRepository; +use Sysvale\Mongodb\Passport\TokenRepository; class MongodbPassportServiceProvider extends ServiceProvider {