diff --git a/.gitignore b/.gitignore index 8ef0e14..a3b8d8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -vendor/ -.idea/ +/vendor +/.idea +/composer.lock diff --git a/src/Http/Controllers/AccessTokenController.php b/src/Http/Controllers/AccessTokenController.php index e6b4651..be5feab 100644 --- a/src/Http/Controllers/AccessTokenController.php +++ b/src/Http/Controllers/AccessTokenController.php @@ -44,9 +44,7 @@ public function issueToken(ServerRequestInterface $request) $tokenId = $this->jwt->parse($payload['access_token'])->getClaim('jti'); $token = $this->tokens->find($tokenId); - if ($token->client->firstParty() && LumenPassport::$allowMultipleTokens) { - // We keep previous tokens for password clients - } else { + if (!$token->client->firstParty() || !LumenPassport::$allowMultipleTokens) { $this->revokeOrDeleteAccessTokens($token, $tokenId); } } @@ -80,7 +78,7 @@ private function makePasswordGrant() */ protected function revokeOrDeleteAccessTokens(Token $token, $tokenId) { - $query = Token::where('user_id', $token->user_id)->where('client_id', $token->client_id); + $query = Passport::token()->where('user_id', $token->user_id)->where('client_id', $token->client_id); if ($tokenId) { $query->where('id', '<>', $tokenId); diff --git a/src/PassportServiceProvider.php b/src/PassportServiceProvider.php index 5508a7a..007c987 100644 --- a/src/PassportServiceProvider.php +++ b/src/PassportServiceProvider.php @@ -3,6 +3,7 @@ namespace Dusterio\LumenPassport; use Dusterio\LumenPassport\Console\Commands\Purge; +use Illuminate\Support\Facades\DB; use Illuminate\Support\ServiceProvider; use Illuminate\Database\Connection; @@ -13,13 +14,15 @@ class PassportServiceProvider extends ServiceProvider { /** - * Bootstrap any application services. - * * @return void */ - public function boot() + public function register() { - $this->app->singleton(Connection::class, function() { + $this->app->singleton(Connection::class, function () { + $conn = env('PASSPORT_CONNECTION'); + if ($conn != null) { + return DB::connection($conn); + } return $this->app['db.connection']; }); @@ -35,10 +38,13 @@ public function boot() ]); } } + /** + * Bootstrap any application services. + * * @return void */ - public function register() + public function boot() { } }