-
Notifications
You must be signed in to change notification settings - Fork 785
Fix »OAuth Client Table Changes« migration snippet in the upgrade guide #1859
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
Changes from all commits
ec884f7
fea16cc
eefdb76
424330f
6b9b0b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -139,20 +139,20 @@ If you prefer to use the new structure, you may create a migration to apply the | |||||
|
||||||
```php | ||||||
Schema::table('oauth_clients', function (Blueprint $table) { | ||||||
$table->after('user_id', function (Blueprint $table) { | ||||||
$table->nullableMorphs('owner'); | ||||||
}); | ||||||
$table->nullableMorphs('owner', after: 'user_id'); | ||||||
|
||||||
$table->after('provider', function (Blueprint $table) { | ||||||
$table->text('redirect_uris'); | ||||||
$table->text('grant_types'); | ||||||
$table->text('grant_types')->nullable(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declare
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
// \Laravel\Passport\Client::grantTypes
Attribute::make(
get: fn (?string $value): array => isset($value) ? $this->fromJson($value) : array_keys(array_filter([
'authorization_code' => ! empty($this->redirect_uris),
'client_credentials' => $this->confidential() && $this->firstParty(),
'implicit' => ! empty($this->redirect_uris),
'password' => $this->password_client,
'personal_access' => $this->personal_access_client && $this->confidential(),
'refresh_token' => true,
'urn:ietf:params:oauth:grant-type:device_code' => true,
])),
); If you default to ⇒ Your suggested change would drop data instead of preserving it.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, so I guess There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // \Laravel\Passport\Client::redirectUris
Attribute::make(
get: fn (?string $value, array $attributes): array => match (true) {
! empty($value) => $this->fromJson($value),
! empty($attributes['redirect']) => explode(',', $attributes['redirect']),
default => [],
},
); I tested it with just one redirect URL as well as multiple URLs joined by commas. It always worked just fine. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should make them both |
||||||
}); | ||||||
}); | ||||||
|
||||||
foreach (Passport::client()->cursor() as $client) { | ||||||
Model::withoutTimestamps(fn () => $client->forceFill([ | ||||||
'owner_id' => $client->user_id, | ||||||
'owner_type' => $client->user_id ? config('auth.providers.'.$client->provider.'.model') : null, | ||||||
'owner_type' => $client->user_id | ||||||
? config('auth.providers.'.($client->provider ?: config('auth.guards.api.provider')).'.model') | ||||||
: null, | ||||||
'redirect_uris' => $client->redirect_uris, | ||||||
'grant_types' => $client->grant_types, | ||||||
])->save()); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passport supports Laravel 11+ but the suggested syntax is available since 12+ AFAIK. Anything wrong with current syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
$table->after('user_id', function (Blueprint $table) { … });
wrap did not work for me in combination with$table->nullableMorphs('owner');
.I didn't check that. If it needs to work on L11 too and the
owner_type
+owner_id
columns should end up right after theuser_id
column, we'd probably have to manually create the individual columns within the$table->after('user_id', function (Blueprint $table) { … });
wrap.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weired, I'll run a test on the framework to make sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was working fine, but a bug /breaking change has been introduced by laravel/framework#56613
Please keep it as is, I'll send a PR to the framework to fix this.