Skip to content

Commit 3d58f57

Browse files
committed
Fixed Laravel passport migrations
1 parent 400bc43 commit 3d58f57

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

database/migrations/2025_06_30_132538_update_oauth_clients_table.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,45 @@ public function up(): void
2121
$table->renameColumn('user_id', 'owner_id');
2222
$table->string('owner_type')->after('owner_id')->nullable();
2323
});
24+
2425
DB::table('oauth_clients')
25-
->where('personal_access_client', 1)
26-
->update(['grant_types' => ['personal_access']]);
27-
DB::table('oauth_clients')
28-
->where('password_client', 1)
29-
->update(['grant_types' => ['password', 'refresh_token']]);
30-
DB::table('oauth_clients')
31-
->where('password_client', 0)
32-
->where('personal_access_client', 0)
33-
->update(['grant_types' => ['client_credentials']]);
26+
->where('redirect', '=', 'http://localhost')
27+
->where('personal_access_client', '=', true)
28+
->update(['redirect' => '']);
3429

3530
DB::table('oauth_clients')
3631
->whereNotNull('owner_id')
3732
->update(['owner_type' => 'user']); // Value might be class name of the owner model, depends on if you use "enforceMorphMap"
3833

3934
DB::table('oauth_clients')->eachById(function ($client): void {
40-
$redirectUris = [$client->redirect];
35+
$grantTypes = ['urn:ietf:params:oauth:grant-type:device_code', 'refresh_token'];
36+
$confidential = ! empty($client->secret);
37+
$noRedirect = empty($client->redirect);
38+
$redirectUris = $noRedirect ? [] : [$client->redirect];
39+
$firstParty = empty($client->owner_id);
40+
41+
if (! $noRedirect) {
42+
$grantTypes[] = 'authorization_code';
43+
$grantTypes[] = 'implicit';
44+
}
45+
46+
if ($confidential && $firstParty) {
47+
$grantTypes[] = 'client_credentials';
48+
}
49+
50+
if ($client->personal_access_client && $confidential) {
51+
$grantTypes[] = 'personal_access';
52+
}
53+
54+
if ($client->password_client) {
55+
$grantTypes[] = 'password';
56+
}
57+
4158
DB::table('oauth_clients')
4259
->where('id', $client->id)
4360
->update([
4461
'redirect_uris' => $redirectUris,
62+
'grant_types' => $grantTypes,
4563
]);
4664
});
4765

database/migrations/2025_07_15_105949_hash_oauth_clients.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public function up(): void
1313
{
1414
// This could be optimized to run all the updates in the eachById
15-
DB::table('oauth_clients')->eachById(function ($client): void {
15+
DB::table('oauth_clients')->whereNotNull('secret')->eachById(function ($client): void {
1616
$secret = $client->secret;
1717
if (Hash::isHashed($secret) && ! Hash::needsRehash($secret)) {
1818
return; // Already hashed and not needing rehash

0 commit comments

Comments
 (0)