From 6d4393e3be8b2ffb8a9e3c270f6ca3b534f0ccf9 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 7 Aug 2020 22:57:40 +0200 Subject: [PATCH] Remove old static personal client methods (#1325) --- src/ClientRepository.php | 51 ++++++++++++++++++++++++++++-- src/Passport.php | 40 ----------------------- src/PassportServiceProvider.php | 15 +++++++++ src/PersonalAccessTokenFactory.php | 2 +- 4 files changed, 65 insertions(+), 43 deletions(-) diff --git a/src/ClientRepository.php b/src/ClientRepository.php index e04dfc0d8..6a6af3902 100644 --- a/src/ClientRepository.php +++ b/src/ClientRepository.php @@ -7,6 +7,33 @@ class ClientRepository { + /** + * The personal access client ID. + * + * @var int|string|null + */ + protected $personalAccessClientId; + + /** + * The personal access client secret. + * + * @var string|null + */ + protected $personalAccessClientSecret; + + /** + * Create a new client repository. + * + * @param int|string|null $personalAccessClientId + * @param string|null $personalAccessClientSecret + * @return void + */ + public function __construct($personalAccessClientId = null, $personalAccessClientSecret = null) + { + $this->personalAccessClientId = $personalAccessClientId; + $this->personalAccessClientSecret = $personalAccessClientSecret; + } + /** * Get a client by the given ID. * @@ -85,8 +112,8 @@ public function activeForUser($userId) */ public function personalAccessClient() { - if (Passport::$personalAccessClientId) { - return $this->find(Passport::$personalAccessClientId); + if ($this->personalAccessClientId) { + return $this->find($this->personalAccessClientId); } $client = Passport::personalAccessClient(); @@ -216,4 +243,24 @@ public function delete(Client $client) $client->forceFill(['revoked' => true])->save(); } + + /** + * Get the personal access client id. + * + * @return int|string|null + */ + public function getPersonalAccessClientId() + { + return $this->personalAccessClientId; + } + + /** + * Get the personal access client secret. + * + * @return string|null + */ + public function getPersonalAccessClientSecret() + { + return $this->personalAccessClientSecret; + } } diff --git a/src/Passport.php b/src/Passport.php index 6113e2923..ecad1944e 100644 --- a/src/Passport.php +++ b/src/Passport.php @@ -19,20 +19,6 @@ class Passport */ public static $implicitGrantEnabled = false; - /** - * The personal access token client ID. - * - * @var int|string - */ - public static $personalAccessClientId; - - /** - * The personal access token client secret. - * - * @var string - */ - public static $personalAccessClientSecret; - /** * The default scope. * @@ -196,32 +182,6 @@ public static function routes($callback = null, array $options = []) }); } - /** - * Set the client ID that should be used to issue personal access tokens. - * - * @param int|string $clientId - * @return static - */ - public static function personalAccessClientId($clientId) - { - static::$personalAccessClientId = $clientId; - - return new static; - } - - /** - * Set the client secret that should be used to issue personal access tokens. - * - * @param string $clientSecret - * @return static - */ - public static function personalAccessClientSecret($clientSecret) - { - static::$personalAccessClientSecret = $clientSecret; - - return new static; - } - /** * Set the default scope(s). Multiple scopes may be an array or specified delimited by spaces. * diff --git a/src/PassportServiceProvider.php b/src/PassportServiceProvider.php index 4a11e62f4..6c6d97439 100644 --- a/src/PassportServiceProvider.php +++ b/src/PassportServiceProvider.php @@ -93,6 +93,7 @@ public function register() Passport::setClientUuids($this->app->make(Config::class)->get('passport.client_uuids', false)); $this->registerAuthorizationServer(); + $this->registerClientRepository(); $this->registerResourceServer(); $this->registerGuard(); } @@ -220,6 +221,20 @@ public function makeAuthorizationServer() ); } + /** + * Register the client repository. + * + * @return void + */ + protected function registerClientRepository() + { + $this->app->singleton(ClientRepository::class, function ($container) { + $config = $container->make('config')->get('passport.personal_access_client'); + + return new ClientRepository($config['id'] ?? null, $config['secret'] ?? null); + }); + } + /** * Register the resource server. * diff --git a/src/PersonalAccessTokenFactory.php b/src/PersonalAccessTokenFactory.php index 27c558d79..34fefcd66 100644 --- a/src/PersonalAccessTokenFactory.php +++ b/src/PersonalAccessTokenFactory.php @@ -93,7 +93,7 @@ public function make($userId, $name, array $scopes = []) */ protected function createRequest($client, $userId, array $scopes) { - $secret = Passport::$hashesClientSecrets ? Passport::$personalAccessClientSecret : $client->secret; + $secret = Passport::$hashesClientSecrets ? $this->clients->getPersonalAccessClientSecret() : $client->secret; return (new ServerRequest)->withParsedBody([ 'grant_type' => 'personal_access',