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/composer.json b/composer.json
index fb36078..73bdd99 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,30 +10,33 @@
"laravel-passport",
"mongodb",
"passport",
- "designmynight"
+ "sysvale"
],
"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"
+ "illuminate/support": "^5.5 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
+ "jenssegers/mongodb": "3.3.* || 3.4.* || 3.5.* || 3.6.* || 3.8.* || 3.9.*",
+ "laravel/passport": "6.0.* || 7.0.* || 7.4.* || 7.5.* || ^8.0 || ^9.0 || ^10 || ^11"
},
"autoload": {
"psr-4": {
- "DesignMyNight\\Mongodb\\": "src"
+ "Sysvale\\Mongodb\\": "src"
}
},
"authors": [
{
"name": "DesignMyNight",
- "email": "support@designmynight.com",
- "role": "Support"
+ "email": "support@designmynight.com"
+ },
+ {
+ "name": "Geidson",
+ "email": "geidson@sysvale.com"
}
],
"extra": {
"laravel": {
"providers": [
- "DesignMyNight\\Mongodb\\MongodbPassportServiceProvider"
+ "Sysvale\\Mongodb\\MongodbPassportServiceProvider"
]
}
}
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 @@
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/Console/PurgeCommand.php b/src/Console/PurgeCommand.php
new file mode 100644
index 0000000..ad6f6f9
--- /dev/null
+++ b/src/Console/PurgeCommand.php
@@ -0,0 +1,37 @@
+subDays(7);
+
+ if (($this->option('revoked') && $this->option('expired')) ||
+ (!$this->option('revoked') && !$this->option('expired'))
+ ) {
+ Passport::token()->where('revoked', true)->orWhere('expires_at', '<', $expired)->delete();
+ Passport::authCode()->where('revoked', true)->orWhere('expires_at', '<', $expired)->delete();
+ Passport::refreshToken()->where('revoked', true)->orWhere('expires_at', '<', $expired)->delete();
+
+ $this->info('Purged revoked items and items expired for more than seven days.');
+ } elseif ($this->option('revoked')) {
+ Passport::token()->where('revoked', true)->delete();
+ Passport::authCode()->where('revoked', true)->delete();
+ Passport::refreshToken()->where('revoked', true)->delete();
+
+ $this->info('Purged revoked items.');
+ } elseif ($this->option('expired')) {
+ Passport::token()->where('expires_at', '<', $expired)->delete();
+ Passport::authCode()->where('expires_at', '<', $expired)->delete();
+ Passport::refreshToken()->where('expires_at', '<', $expired)->delete();
+
+ $this->info('Purged items expired for more than seven days.');
+ }
+ }
+}
diff --git a/src/MongodbPassportServiceProvider.php b/src/MongodbPassportServiceProvider.php
index 37723a3..a81f320 100644
--- a/src/MongodbPassportServiceProvider.php
+++ b/src/MongodbPassportServiceProvider.php
@@ -1,31 +1,50 @@
app->bind(PassportRefreshTokenRepository::class, function () {
return $this->app->make(RefreshTokenRepository::class);
});
+
+ $this->app->extend(PassportClientCommand::class, function () {
+ return new ClientCommand();
+ });
+
+ $this->app->extend(PassportPurgeCommand::class, function () {
+ return new PurgeCommand();
+ });
+
+ $this->app->bind(PassportTokenRepository::class, function () {
+ return $this->app->make(TokenRepository::class);
+ });
}
}
diff --git a/src/Passport/AuthCode.php b/src/Passport/AuthCode.php
index c920a3d..f483936 100644
--- a/src/Passport/AuthCode.php
+++ b/src/Passport/AuthCode.php
@@ -1,6 +1,6 @@
save();
+ }
+
+}