Skip to content

Commit 57931ae

Browse files
[13.x] Remove redundant PAT client table and model (#1749)
* remove redundant PAT table and model * wip * Update UPGRADE.md * Update ClientRepository.php * Update ClientCommand.php * Update ClientCommand.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 2e44a19 commit 57931ae

8 files changed

+19
-143
lines changed

UPGRADE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ Passport now always hashes client secrets using Laravel's `Hash` facade. If you
2626

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

29+
### Personal Access Client Table and Model Removal
30+
31+
PR: https://github.com/laravel/passport/pull/1749
32+
33+
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:
34+
35+
Schema::drop('oauth_personal_access_clients');
36+
37+
In addition, the `Laravel\Passport\PersonalAccessClient` model, `Passport::$personalAccessClientModel` property, `Passport::usePersonalAccessClientModel()`, `Passport::personalAccessClientModel()`, and `Passport::personalAccessClient()` methods have been removed.
38+
2939
## Upgrading To 12.0 From 11.x
3040

3141
### Migration Changes

database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/ClientRepository.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,11 @@ public function activeForUser($userId)
112112
*/
113113
public function personalAccessClient()
114114
{
115-
if ($this->personalAccessClientId) {
116-
return $this->find($this->personalAccessClientId);
117-
}
115+
$client = $this->personalAccessClientId ? $this->find($this->personalAccessClientId) : null;
118116

119-
$client = Passport::personalAccessClient();
120-
121-
if (! $client->exists()) {
122-
throw new RuntimeException('Personal access client not found. Please create one.');
123-
}
124-
125-
return $client->orderBy($client->getKeyName(), 'desc')->first()->client;
117+
return $client ?? throw new RuntimeException(
118+
'Personal access client not found. Please create one and set the `PASSPORT_PERSONAL_ACCESS_CLIENT_ID` and `PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET` environment variables.'
119+
);
126120
}
127121

128122
/**
@@ -165,11 +159,7 @@ public function create($userId, $name, $redirect, $provider = null, $personalAcc
165159
*/
166160
public function createPersonalAccessClient($userId, $name, $redirect)
167161
{
168-
return tap($this->create($userId, $name, $redirect, null, true), function ($client) {
169-
$accessClient = Passport::personalAccessClient();
170-
$accessClient->client_id = $client->getKey();
171-
$accessClient->save();
172-
});
162+
return $this->create($userId, $name, $redirect, null, true);
173163
}
174164

175165
/**

src/Console/ClientCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ protected function createPersonalClient(ClientRepository $clients)
7070

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

73+
if (! config('passport.personal_access_client')) {
74+
$this->components->info('Next, define the `PASSPORT_PERSONAL_ACCESS_CLIENT_ID` and `PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET` environment variables using the values below.');
75+
}
76+
7377
$this->outputClientDetails($client);
7478
}
7579

src/Console/InstallCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ protected function configureUuids()
6969
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_auth_codes_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
7070
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_access_tokens_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
7171
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_clients_table.php'), '$table->bigIncrements(\'id\');', '$table->uuid(\'id\')->primary();');
72-
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_personal_access_clients_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
7372
}
7473

7574
/**

src/Passport.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,6 @@ class Passport
121121
*/
122122
public static $clientUuids = false;
123123

124-
/**
125-
* The personal access client model class name.
126-
*
127-
* @var string
128-
*/
129-
public static $personalAccessClientModel = 'Laravel\Passport\PersonalAccessClient';
130-
131124
/**
132125
* The token model class name.
133126
*
@@ -551,37 +544,6 @@ public static function setClientUuids($value)
551544
static::$clientUuids = $value;
552545
}
553546

554-
/**
555-
* Set the personal access client model class name.
556-
*
557-
* @param string $clientModel
558-
* @return void
559-
*/
560-
public static function usePersonalAccessClientModel($clientModel)
561-
{
562-
static::$personalAccessClientModel = $clientModel;
563-
}
564-
565-
/**
566-
* Get the personal access client model class name.
567-
*
568-
* @return string
569-
*/
570-
public static function personalAccessClientModel()
571-
{
572-
return static::$personalAccessClientModel;
573-
}
574-
575-
/**
576-
* Get a new personal access client model instance.
577-
*
578-
* @return \Laravel\Passport\PersonalAccessClient
579-
*/
580-
public static function personalAccessClient()
581-
{
582-
return new static::$personalAccessClientModel;
583-
}
584-
585547
/**
586548
* Set the token model class name.
587549
*

src/PersonalAccessClient.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/Unit/PassportTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Laravel\Passport\Client;
77
use Laravel\Passport\ClientRepository;
88
use Laravel\Passport\Passport;
9-
use Laravel\Passport\PersonalAccessClient;
109
use Laravel\Passport\RefreshToken;
1110
use Laravel\Passport\Token;
1211
use PHPUnit\Framework\TestCase;
@@ -40,20 +39,10 @@ public function test_client_instance_can_be_created()
4039
$this->assertInstanceOf(Passport::clientModel(), $client);
4140
}
4241

43-
public function test_personal_access_client_instance_can_be_created()
44-
{
45-
$client = Passport::personalAccessClient();
46-
47-
$this->assertInstanceOf(PersonalAccessClient::class, $client);
48-
$this->assertInstanceOf(Passport::personalAccessClientModel(), $client);
49-
}
50-
5142
public function test_missing_personal_access_client_is_reported()
5243
{
5344
$this->expectException('RuntimeException');
5445

55-
Passport::usePersonalAccessClientModel(PersonalAccessClientStub::class);
56-
5746
$clientRepository = new ClientRepository;
5847
$clientRepository->personalAccessClient();
5948
}
@@ -87,14 +76,6 @@ public function test_refresh_token_model_can_be_changed()
8776
}
8877
}
8978

90-
class PersonalAccessClientStub
91-
{
92-
public function exists()
93-
{
94-
return false;
95-
}
96-
}
97-
9879
class RefreshTokenStub
9980
{
10081
}

0 commit comments

Comments
 (0)