From 40bb467620ccc79d89208f2874f528dbfbe3362c Mon Sep 17 00:00:00 2001 From: Matthew Hatcher Date: Fri, 23 Mar 2018 02:06:08 -0400 Subject: [PATCH] Adding optional configuration. --- config/passport.php | 7 +++++++ src/Client.php | 2 +- src/HasApiTokens.php | 2 +- src/Passport.php | 2 +- src/PassportServiceProvider.php | 4 ++++ src/TokenRepository.php | 10 +++++----- 6 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 config/passport.php diff --git a/config/passport.php b/config/passport.php new file mode 100644 index 000000000..e628348f7 --- /dev/null +++ b/config/passport.php @@ -0,0 +1,7 @@ + [ + 'model' => Laravel\Passport\Token::class, + ], +]; \ No newline at end of file diff --git a/src/Client.php b/src/Client.php index 23d8009c6..46df99adf 100644 --- a/src/Client.php +++ b/src/Client.php @@ -57,7 +57,7 @@ public function authCodes() */ public function tokens() { - return $this->hasMany(Token::class, 'client_id'); + return $this->hasMany(config('passport.token.model', Laravel\Passport\Token::class), 'client_id'); } /** diff --git a/src/HasApiTokens.php b/src/HasApiTokens.php index 528b733a2..4d27be3d1 100644 --- a/src/HasApiTokens.php +++ b/src/HasApiTokens.php @@ -30,7 +30,7 @@ public function clients() */ public function tokens() { - return $this->hasMany(Token::class, 'user_id')->orderBy('created_at', 'desc'); + return $this->hasMany(config('passport.token.model', Laravel\Passport\Token::class), 'user_id')->orderBy('created_at', 'desc'); } /** diff --git a/src/Passport.php b/src/Passport.php index 35d5bd2a9..f7eeb8066 100644 --- a/src/Passport.php +++ b/src/Passport.php @@ -282,7 +282,7 @@ public static function cookie($cookie = null) */ public static function actingAs($user, $scopes = [], $guard = 'api') { - $token = Mockery::mock(Token::class)->shouldIgnoreMissing(false); + $token = Mockery::mock(config('passport.token.model', Laravel\Passport\Token::class))->shouldIgnoreMissing(false); foreach ($scopes as $scope) { $token->shouldReceive('can')->with($scope)->andReturn(true); diff --git a/src/PassportServiceProvider.php b/src/PassportServiceProvider.php index d1b8b8993..01a4a5734 100644 --- a/src/PassportServiceProvider.php +++ b/src/PassportServiceProvider.php @@ -46,6 +46,10 @@ public function boot() __DIR__.'/../resources/assets/js/components' => base_path('resources/assets/js/components/passport'), ], 'passport-components'); + $this->publishes([ + __DIR__.'/../config/passport.php' => config_path('passport.php'), + ], 'passport-config'); + $this->commands([ Console\InstallCommand::class, Console\ClientCommand::class, diff --git a/src/TokenRepository.php b/src/TokenRepository.php index 585eeedd0..a1b5ac979 100644 --- a/src/TokenRepository.php +++ b/src/TokenRepository.php @@ -15,7 +15,7 @@ class TokenRepository */ public function create($attributes) { - return Token::create($attributes); + return config('passport.token.model', Laravel\Passport\Token::class)::create($attributes); } /** @@ -26,7 +26,7 @@ public function create($attributes) */ public function find($id) { - return Token::find($id); + return config('passport.token.model', Laravel\Passport\Token::class)::find($id); } /** @@ -38,7 +38,7 @@ public function find($id) */ public function findForUser($id, $userId) { - return Token::where('id', $id)->where('user_id', $userId)->first(); + return config('passport.token.model', Laravel\Passport\Token::class)::where('id', $id)->where('user_id', $userId)->first(); } /** @@ -49,7 +49,7 @@ public function findForUser($id, $userId) */ public function forUser($userId) { - return Token::where('user_id', $userId)->get(); + return config('passport.token.model', Laravel\Passport\Token::class)::where('user_id', $userId)->get(); } /** @@ -87,7 +87,7 @@ public function save(Token $token) */ public function revokeAccessToken($id) { - return Token::where('id', $id)->update(['revoked' => true]); + return config('passport.token.model', Laravel\Passport\Token::class)::where('id', $id)->update(['revoked' => true]); } /**