Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/support token mongo #59

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ 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
<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use DesignMyNight\Mongodb\Auth\User as Authenticatable;
use Sysvale\Mongodb\Auth\User as Authenticatable;

class User extends Authenticatable
{
Expand All @@ -41,17 +41,17 @@ class User extends Authenticatable
5.5.x | 4.0.x, 5.0.x, 6.0.x, 7.0.x | 1.1.x
5.6.x | 4.0.x, 5.0.x, 6.0.x, 7.0.x | 1.1.x
6.x | 4.0.x, 5.0.x, 6.0.x, 7.x, 8.x| 1.2.x

And add the service provider in `config/app.php`:

```php
DesignMyNight\Mongodb\MongodbPassportServiceProvider::class,
Sysvale\Mongodb\MongodbPassportServiceProvider::class,
```

For usage with [Lumen](http://lumen.laravel.com), add the service provider in `bootstrap/app.php`.

```php
$app->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).
20 changes: 12 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -10,30 +10,34 @@
"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",
"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": {
"DesignMyNight\\Mongodb\\": "src"
"Sysvale\\Mongodb\\": "src"
}
},
"authors": [
{
"name": "DesignMyNight",
"email": "support@designmynight.com",
"role": "Support"
},
{
"name": "Geidson",
"email": "geidson@sysvale.com"
}
],
"extra": {
"laravel": {
"providers": [
"DesignMyNight\\Mongodb\\MongodbPassportServiceProvider"
"Sysvale\\Mongodb\\MongodbPassportServiceProvider"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/User.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DesignMyNight\Mongodb\Auth;
namespace Sysvale\Mongodb\Auth;

use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
Expand Down
118 changes: 118 additions & 0 deletions src/Console/ClientCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace Sysvale\Mongodb\Console;

use Sysvale\Mongodb\Passport\Client;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Console\ClientCommand as PassportClientCommand;

class ClientCommand extends PassportClientCommand
{
/**
* Create a new personal access client.
*
* @param \Laravel\Passport\ClientRepository $clients
* @return void
*/
protected function createPersonalClient(ClientRepository $clients)
{
$name = $this->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('<comment>Client ID:</comment> '.$client->id);
$this->line('<comment>Client secret:</comment> '.$client->secret);
}
}
29 changes: 20 additions & 9 deletions src/MongodbPassportServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php

namespace DesignMyNight\Mongodb;
namespace Sysvale\Mongodb;

use Illuminate\Support\ServiceProvider;
use DesignMyNight\Mongodb\Passport\AuthCode;
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 Sysvale\Mongodb\Passport\AuthCode;
use Sysvale\Mongodb\Console\ClientCommand;
use Sysvale\Mongodb\Passport\Bridge\RefreshTokenRepository;
use Sysvale\Mongodb\Passport\Client;
use Sysvale\Mongodb\Passport\PersonalAccessClient;
use Sysvale\Mongodb\Passport\Token;
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
{
/**
* @return void
*/
* @return void
*/
public function register()
{
Passport::useAuthCodeModel(AuthCode::class);
Expand All @@ -27,5 +30,13 @@ public function register()
$this->app->bind(PassportRefreshTokenRepository::class, function () {
return $this->app->make(RefreshTokenRepository::class);
});

$this->app->extend(PassportClientCommand::class, function () {
return new ClientCommand();
});

$this->app->bind(PassportTokenRepository::class, function () {
return $this->app->make(TokenRepository::class);
});
}
}
2 changes: 1 addition & 1 deletion src/Passport/AuthCode.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DesignMyNight\Mongodb\Passport;
namespace Sysvale\Mongodb\Passport;

use Jenssegers\Mongodb\Eloquent\Model;

Expand Down
4 changes: 2 additions & 2 deletions src/Passport/Bridge/RefreshToken.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DesignMyNight\Mongodb\Passport\Bridge;
namespace Sysvale\Mongodb\Passport\Bridge;

use Jenssegers\Mongodb\Eloquent\Model;
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
Expand All @@ -9,7 +9,7 @@

/**
* Class RefreshToken
* @package DesignMyNight\Mongodb\Passport\Bridge
* @package Sysvale\Mongodb\Passport\Bridge
*/
class RefreshToken extends Model implements RefreshTokenEntityInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Passport/Bridge/RefreshTokenRepository.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DesignMyNight\Mongodb\Passport\Bridge;
namespace Sysvale\Mongodb\Passport\Bridge;

use Laravel\Passport\Bridge\RefreshTokenRepository as BaseRefreshTokenRepository;
use Laravel\Passport\Events\RefreshTokenCreated;
Expand Down
4 changes: 2 additions & 2 deletions src/Passport/Client.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DesignMyNight\Mongodb\Passport;
namespace Sysvale\Mongodb\Passport;

use Jenssegers\Mongodb\Eloquent\Model;

Expand Down Expand Up @@ -79,7 +79,7 @@ public function skipsAuthorization()
{
return false;
}

/**
* Determine if the client is a confidential client.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Passport/PersonalAccessClient.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DesignMyNight\Mongodb\Passport;
namespace Sysvale\Mongodb\Passport;

use Jenssegers\Mongodb\Eloquent\Model;

Expand Down
2 changes: 1 addition & 1 deletion src/Passport/PersonalAccessTokenFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DesignMyNight\Mongodb\Passport;
namespace Sysvale\Mongodb\Passport;

use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequest;
Expand Down
4 changes: 2 additions & 2 deletions src/Passport/RefreshToken.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
<?php

namespace DesignMyNight\Mongodb\Passport;
namespace Sysvale\Mongodb\Passport;

use Jenssegers\Mongodb\Eloquent\Model;

Expand Down
2 changes: 1 addition & 1 deletion src/Passport/Token.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DesignMyNight\Mongodb\Passport;
namespace Sysvale\Mongodb\Passport;

use Jenssegers\Mongodb\Eloquent\Model;

Expand Down
21 changes: 21 additions & 0 deletions src/Passport/TokenRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Sysvale\Mongodb\Passport;

use Laravel\Passport\TokenRepository as PassportTokenRepository;

class TokenRepository extends PassportTokenRepository
{
/**
* Store the given token instance.
*
* @param \Laravel\Passport\Token $token
* @return void
*/

public function save($token)
{
$token->save();
}

}