mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-16 04:02:15 +01:00
Fixed Laravel passport migrations
This commit is contained in:
@@ -21,27 +21,45 @@ return new class extends Migration
|
|||||||
$table->renameColumn('user_id', 'owner_id');
|
$table->renameColumn('user_id', 'owner_id');
|
||||||
$table->string('owner_type')->after('owner_id')->nullable();
|
$table->string('owner_type')->after('owner_id')->nullable();
|
||||||
});
|
});
|
||||||
|
|
||||||
DB::table('oauth_clients')
|
DB::table('oauth_clients')
|
||||||
->where('personal_access_client', 1)
|
->where('redirect', '=', 'http://localhost')
|
||||||
->update(['grant_types' => ['personal_access']]);
|
->where('personal_access_client', '=', true)
|
||||||
DB::table('oauth_clients')
|
->update(['redirect' => '']);
|
||||||
->where('password_client', 1)
|
|
||||||
->update(['grant_types' => ['password', 'refresh_token']]);
|
|
||||||
DB::table('oauth_clients')
|
|
||||||
->where('password_client', 0)
|
|
||||||
->where('personal_access_client', 0)
|
|
||||||
->update(['grant_types' => ['client_credentials']]);
|
|
||||||
|
|
||||||
DB::table('oauth_clients')
|
DB::table('oauth_clients')
|
||||||
->whereNotNull('owner_id')
|
->whereNotNull('owner_id')
|
||||||
->update(['owner_type' => 'user']); // Value might be class name of the owner model, depends on if you use "enforceMorphMap"
|
->update(['owner_type' => 'user']); // Value might be class name of the owner model, depends on if you use "enforceMorphMap"
|
||||||
|
|
||||||
DB::table('oauth_clients')->eachById(function ($client): void {
|
DB::table('oauth_clients')->eachById(function ($client): void {
|
||||||
$redirectUris = [$client->redirect];
|
$grantTypes = ['urn:ietf:params:oauth:grant-type:device_code', 'refresh_token'];
|
||||||
|
$confidential = ! empty($client->secret);
|
||||||
|
$noRedirect = empty($client->redirect);
|
||||||
|
$redirectUris = $noRedirect ? [] : [$client->redirect];
|
||||||
|
$firstParty = empty($client->owner_id);
|
||||||
|
|
||||||
|
if (! $noRedirect) {
|
||||||
|
$grantTypes[] = 'authorization_code';
|
||||||
|
$grantTypes[] = 'implicit';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($confidential && $firstParty) {
|
||||||
|
$grantTypes[] = 'client_credentials';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($client->personal_access_client && $confidential) {
|
||||||
|
$grantTypes[] = 'personal_access';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($client->password_client) {
|
||||||
|
$grantTypes[] = 'password';
|
||||||
|
}
|
||||||
|
|
||||||
DB::table('oauth_clients')
|
DB::table('oauth_clients')
|
||||||
->where('id', $client->id)
|
->where('id', $client->id)
|
||||||
->update([
|
->update([
|
||||||
'redirect_uris' => $redirectUris,
|
'redirect_uris' => $redirectUris,
|
||||||
|
'grant_types' => $grantTypes,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ return new class extends Migration
|
|||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
// This could be optimized to run all the updates in the eachById
|
// This could be optimized to run all the updates in the eachById
|
||||||
DB::table('oauth_clients')->eachById(function ($client): void {
|
DB::table('oauth_clients')->whereNotNull('secret')->eachById(function ($client): void {
|
||||||
$secret = $client->secret;
|
$secret = $client->secret;
|
||||||
if (Hash::isHashed($secret) && ! Hash::needsRehash($secret)) {
|
if (Hash::isHashed($secret) && ! Hash::needsRehash($secret)) {
|
||||||
return; // Already hashed and not needing rehash
|
return; // Already hashed and not needing rehash
|
||||||
|
|||||||
Reference in New Issue
Block a user