Skip to content

Commit ba3ec9d

Browse files
[13.x] Use UUID to identify clients by default (#1764)
* use uuid for clients by default * update the upgrade guide * Update UPGRADE.md --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent b2bb7df commit ba3ec9d

9 files changed

+24
-88
lines changed

UPGRADE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ PR: https://github.com/laravel/passport/pull/1734
2222

2323
The `league/oauth2-server` Composer package which is utilized internally by Passport has been updated to 9.0, which adds additional types to method signatures. To ensure your application is compatible, you should review this package's complete [changelog](https://github.com/thephpleague/oauth2-server/blob/master/CHANGELOG.md#900---released-2024-05-13).
2424

25+
### Identify Clients by UUIDs
26+
27+
PR: https://github.com/laravel/passport/pull/1764
28+
29+
By default, Passport now uses UUIDs to identify clients. You may keep using incremental integer IDs by setting `Passport::$clientUuids` to `false` within the `boot` method of your application's `App\Providers\AppServiceProvider` class:
30+
31+
public function boot(): void
32+
{
33+
Passport::$clientUuids = false;
34+
}
35+
36+
As a consequence of this change, the `'passport.client_uuids'` configuration property has been removed, as well as the `Passport::clientUuids()` and `Passport::setClientUuids()` methods.
37+
2538
### Client Secrets Hashed by Default
2639

2740
PR: https://github.com/laravel/passport/pull/1745

config/passport.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@
4343

4444
'connection' => env('PASSPORT_CONNECTION'),
4545

46-
/*
47-
|--------------------------------------------------------------------------
48-
| Client UUIDs
49-
|--------------------------------------------------------------------------
50-
|
51-
| By default, Passport uses auto-incrementing primary keys when assigning
52-
| IDs to clients. However, if Passport is installed using the provided
53-
| --uuids switch, this will be set to "true" and UUIDs will be used.
54-
|
55-
*/
56-
57-
'client_uuids' => false,
58-
5946
/*
6047
|--------------------------------------------------------------------------
6148
| Personal Access Client

database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function up(): void
1414
Schema::create('oauth_auth_codes', function (Blueprint $table) {
1515
$table->char('id', 80)->primary();
1616
$table->foreignId('user_id')->index();
17-
$table->foreignId('client_id');
17+
$table->foreignUuid('client_id');
1818
$table->text('scopes')->nullable();
1919
$table->boolean('revoked');
2020
$table->dateTime('expires_at')->nullable();

database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function up(): void
1414
Schema::create('oauth_access_tokens', function (Blueprint $table) {
1515
$table->char('id', 80)->primary();
1616
$table->foreignId('user_id')->nullable()->index();
17-
$table->foreignId('client_id');
17+
$table->foreignUuid('client_id');
1818
$table->string('name')->nullable();
1919
$table->text('scopes')->nullable();
2020
$table->boolean('revoked');

database/migrations/2016_06_01_000004_create_oauth_clients_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
public function up(): void
1313
{
1414
Schema::create('oauth_clients', function (Blueprint $table) {
15-
$table->id();
15+
$table->uuid('id')->primary();
1616
$table->foreignId('user_id')->nullable()->index();
1717
$table->string('name');
18-
$table->string('secret', 100)->nullable();
18+
$table->string('secret')->nullable();
1919
$table->string('provider')->nullable();
2020
$table->text('redirect');
2121
$table->boolean('personal_access_client');

src/Client.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function __construct(array $attributes = [])
6868
{
6969
parent::__construct($attributes);
7070

71-
$this->usesUniqueIds = Passport::clientUuids();
71+
$this->usesUniqueIds = Passport::$clientUuids;
7272
}
7373

7474
/**
@@ -209,7 +209,7 @@ public function confidential()
209209
*/
210210
public function uniqueIds()
211211
{
212-
return Passport::clientUuids() ? [$this->getKeyName()] : [];
212+
return $this->usesUniqueIds ? [$this->getKeyName()] : [];
213213
}
214214

215215
/**
@@ -219,7 +219,7 @@ public function uniqueIds()
219219
*/
220220
public function newUniqueId()
221221
{
222-
return Passport::clientUuids() ? (string) Str::orderedUuid() : null;
222+
return $this->usesUniqueIds ? (string) Str::orderedUuid() : null;
223223
}
224224

225225
/**
@@ -229,7 +229,7 @@ public function newUniqueId()
229229
*/
230230
public function getKeyType()
231231
{
232-
return Passport::clientUuids() ? 'string' : $this->keyType;
232+
return $this->usesUniqueIds ? 'string' : $this->keyType;
233233
}
234234

235235
/**
@@ -239,7 +239,7 @@ public function getKeyType()
239239
*/
240240
public function getIncrementing()
241241
{
242-
return Passport::clientUuids() ? false : $this->incrementing;
242+
return $this->usesUniqueIds ? false : $this->incrementing;
243243
}
244244

245245
/**

src/Console/InstallCommand.php

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Laravel\Passport\Console;
44

55
use Illuminate\Console\Command;
6-
use Laravel\Passport\Passport;
76
use Symfony\Component\Console\Attribute\AsCommand;
87

98
#[AsCommand(name: 'passport:install')]
@@ -15,7 +14,6 @@ class InstallCommand extends Command
1514
* @var string
1615
*/
1716
protected $signature = 'passport:install
18-
{--uuids : Use UUIDs for all client IDs}
1917
{--force : Overwrite keys they already exist}
2018
{--length=4096 : The length of the private key}';
2119

@@ -35,12 +33,9 @@ public function handle()
3533
{
3634
$this->call('passport:keys', ['--force' => $this->option('force'), '--length' => $this->option('length')]);
3735

36+
$this->call('vendor:publish', ['--tag' => 'passport-config']);
3837
$this->call('vendor:publish', ['--tag' => 'passport-migrations']);
3938

40-
if ($this->option('uuids')) {
41-
$this->configureUuids();
42-
}
43-
4439
if ($this->confirm('Would you like to run all pending database migrations?', true)) {
4540
$this->call('migrate');
4641

@@ -49,40 +44,4 @@ public function handle()
4944
}
5045
}
5146
}
52-
53-
/**
54-
* Configure Passport for client UUIDs.
55-
*
56-
* @return void
57-
*/
58-
protected function configureUuids()
59-
{
60-
$this->call('vendor:publish', ['--tag' => 'passport-config']);
61-
62-
config(['passport.client_uuids' => true]);
63-
Passport::setClientUuids(true);
64-
65-
$this->replaceInFile(config_path('passport.php'), '\'client_uuids\' => false', '\'client_uuids\' => true');
66-
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_auth_codes_table.php'), '$table->foreignId(\'client_id\');', '$table->foreignUuid(\'client_id\');');
67-
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_access_tokens_table.php'), '$table->foreignId(\'client_id\');', '$table->foreignUuid(\'client_id\');');
68-
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_clients_table.php'), '$table->id();', '$table->uuid(\'id\')->primary();');
69-
}
70-
71-
/**
72-
* Replace a given string in a given file.
73-
*
74-
* @param string $path
75-
* @param string $search
76-
* @param string $replace
77-
* @return void
78-
*/
79-
protected function replaceInFile($path, $search, $replace)
80-
{
81-
foreach (glob($path) as $file) {
82-
file_put_contents(
83-
$file,
84-
str_replace($search, $replace, file_get_contents($file))
85-
);
86-
}
87-
}
8847
}

src/Passport.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Passport
119119
*
120120
* @var bool
121121
*/
122-
public static $clientUuids = false;
122+
public static $clientUuids = true;
123123

124124
/**
125125
* The token model class name.
@@ -511,27 +511,6 @@ public static function client()
511511
return new static::$clientModel;
512512
}
513513

514-
/**
515-
* Determine if clients are identified using UUIDs.
516-
*
517-
* @return bool
518-
*/
519-
public static function clientUuids()
520-
{
521-
return static::$clientUuids;
522-
}
523-
524-
/**
525-
* Specify if clients are identified using UUIDs.
526-
*
527-
* @param bool $value
528-
* @return void
529-
*/
530-
public static function setClientUuids($value)
531-
{
532-
static::$clientUuids = $value;
533-
}
534-
535514
/**
536515
* Set the token model class name.
537516
*

src/PassportServiceProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ public function register()
126126
{
127127
$this->mergeConfigFrom(__DIR__.'/../config/passport.php', 'passport');
128128

129-
Passport::setClientUuids($this->app->make(Config::class)->get('passport.client_uuids', false));
130-
131129
$this->app->when(AuthorizationController::class)
132130
->needs(StatefulGuard::class)
133131
->give(fn () => Auth::guard(config('passport.guard', null)));

0 commit comments

Comments
 (0)