Skip to content

[13.x] Remove redundant PAT client table and model #1749

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

Merged
merged 7 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ Passport now always hashes client secrets using Laravel's `Hash` facade. If you

In light of this change, the `Passport::$hashesClientSecrets` property and `Passport::hashClientSecrets()` method has been removed.

### Personal Access Client Table and Model Removal

PR: https://github.com/laravel/passport/pull/1749

Passport's `oauth_personal_access_clients` table has been redundant and unnecessary for several release cycles. Therefore, this release of Passport no longer interacts with this table or its corresponding model. If you wish, you may create a migration that drops this table:

Schema::drop('oauth_personal_access_clients');

In addition, the `Laravel\Passport\PersonalAccessClient` model, `Passport::$personalAccessClientModel` property, `Passport::usePersonalAccessClientModel()`, `Passport::personalAccessClientModel()`, and `Passport::personalAccessClient()` methods have been removed.

## Upgrading To 12.0 From 11.x

### Migration Changes
Expand Down

This file was deleted.

20 changes: 5 additions & 15 deletions src/ClientRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,11 @@ public function activeForUser($userId)
*/
public function personalAccessClient()
{
if ($this->personalAccessClientId) {
return $this->find($this->personalAccessClientId);
}
$client = $this->personalAccessClientId ? $this->find($this->personalAccessClientId) : null;

$client = Passport::personalAccessClient();

if (! $client->exists()) {
throw new RuntimeException('Personal access client not found. Please create one.');
}

return $client->orderBy($client->getKeyName(), 'desc')->first()->client;
return $client ?? throw new RuntimeException(
'Personal access client not found. Please create one and set the `PASSPORT_PERSONAL_ACCESS_CLIENT_ID` and `PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET` environment variables.'
);
}

/**
Expand Down Expand Up @@ -165,11 +159,7 @@ public function create($userId, $name, $redirect, $provider = null, $personalAcc
*/
public function createPersonalAccessClient($userId, $name, $redirect)
{
return tap($this->create($userId, $name, $redirect, null, true), function ($client) {
$accessClient = Passport::personalAccessClient();
$accessClient->client_id = $client->getKey();
$accessClient->save();
});
return $this->create($userId, $name, $redirect, null, true);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Console/ClientCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ protected function createPersonalClient(ClientRepository $clients)

$this->components->info('Personal access client created successfully.');

if (! config('passport.personal_access_client')) {
$this->components->info('Next, define the `PASSPORT_PERSONAL_ACCESS_CLIENT_ID` and `PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET` environment variables using the values below.');
}

$this->outputClientDetails($client);
}

Expand Down
1 change: 0 additions & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ protected function configureUuids()
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_auth_codes_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_access_tokens_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_clients_table.php'), '$table->bigIncrements(\'id\');', '$table->uuid(\'id\')->primary();');
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_personal_access_clients_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
}

/**
Expand Down
38 changes: 0 additions & 38 deletions src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ class Passport
*/
public static $clientUuids = false;

/**
* The personal access client model class name.
*
* @var string
*/
public static $personalAccessClientModel = 'Laravel\Passport\PersonalAccessClient';

/**
* The token model class name.
*
Expand Down Expand Up @@ -551,37 +544,6 @@ public static function setClientUuids($value)
static::$clientUuids = $value;
}

/**
* Set the personal access client model class name.
*
* @param string $clientModel
* @return void
*/
public static function usePersonalAccessClientModel($clientModel)
{
static::$personalAccessClientModel = $clientModel;
}

/**
* Get the personal access client model class name.
*
* @return string
*/
public static function personalAccessClientModel()
{
return static::$personalAccessClientModel;
}

/**
* Get a new personal access client model instance.
*
* @return \Laravel\Passport\PersonalAccessClient
*/
public static function personalAccessClient()
{
return new static::$personalAccessClientModel;
}

/**
* Set the token model class name.
*
Expand Down
42 changes: 0 additions & 42 deletions src/PersonalAccessClient.php

This file was deleted.

19 changes: 0 additions & 19 deletions tests/Unit/PassportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Laravel\Passport\Client;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Passport;
use Laravel\Passport\PersonalAccessClient;
use Laravel\Passport\RefreshToken;
use Laravel\Passport\Token;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -40,20 +39,10 @@ public function test_client_instance_can_be_created()
$this->assertInstanceOf(Passport::clientModel(), $client);
}

public function test_personal_access_client_instance_can_be_created()
{
$client = Passport::personalAccessClient();

$this->assertInstanceOf(PersonalAccessClient::class, $client);
$this->assertInstanceOf(Passport::personalAccessClientModel(), $client);
}

public function test_missing_personal_access_client_is_reported()
{
$this->expectException('RuntimeException');

Passport::usePersonalAccessClientModel(PersonalAccessClientStub::class);

$clientRepository = new ClientRepository;
$clientRepository->personalAccessClient();
}
Expand Down Expand Up @@ -87,14 +76,6 @@ public function test_refresh_token_model_can_be_changed()
}
}

class PersonalAccessClientStub
{
public function exists()
{
return false;
}
}

class RefreshTokenStub
{
}