Skip to content

Commit

Permalink
Remove old static personal client methods (#1325)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Aug 7, 2020
1 parent 995b3f2 commit 6d4393e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 43 deletions.
51 changes: 49 additions & 2 deletions src/ClientRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
40 changes: 0 additions & 40 deletions src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
15 changes: 15 additions & 0 deletions src/PassportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/PersonalAccessTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6d4393e

Please sign in to comment.