Skip to content

Commit 664bc3f

Browse files
authored
Merge pull request #8823 from ProcessMaker/bugfix/FOUR-31130
FOUR-31151 Fix issue when oauth client id is the same as the user id
2 parents e3be6ec + 123596c commit 664bc3f

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
use Illuminate\Database\Eloquent\Model;
4+
use Illuminate\Database\Migrations\Migration;
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Support\Facades\Schema;
7+
use Laravel\Passport\Passport;
8+
9+
return new class extends Migration {
10+
/**
11+
* Run the migrations.
12+
*/
13+
public function up(): void
14+
{
15+
// Copied from https://github.com/jaapredeker/passport/blob/021ab9adafbbaed1d600869ca891586ca99b2f49/UPGRADE.md#oauth-client-table-changes
16+
17+
Schema::table('oauth_clients', function (Blueprint $table) {
18+
$table->nullableMorphs('owner', after: 'user_id');
19+
20+
$table->after('provider', function (Blueprint $table) {
21+
$table->text('redirect_uris')->nullable();
22+
$table->text('grant_types')->nullable();
23+
});
24+
});
25+
26+
foreach (Passport::client()->cursor() as $client) {
27+
if ($client->personal_access_client === true && $client->password_client === false) {
28+
$grantTypes = ['personal_access'];
29+
} else {
30+
$grantTypes = $client->grant_types;
31+
}
32+
Model::withoutTimestamps(fn () => $client->forceFill([
33+
'owner_id' => $client->user_id,
34+
'owner_type' => $client->user_id
35+
? config('auth.providers.' . ($client->provider ?: config('auth.guards.api.provider')) . '.model')
36+
: null,
37+
'redirect_uris' => $client->redirect_uris,
38+
'grant_types' => $grantTypes,
39+
])->save());
40+
}
41+
42+
Schema::table('oauth_clients', function (Blueprint $table) {
43+
$table->dropColumn(['user_id', 'redirect', 'personal_access_client', 'password_client']);
44+
45+
$table->text('redirect_uris')->nullable(false)->change();
46+
$table->text('grant_types')->nullable(false)->change();
47+
});
48+
}
49+
50+
/**
51+
* Reverse the migrations.
52+
*/
53+
public function down(): void
54+
{
55+
//
56+
}
57+
};

database/seeders/UserSeeder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public function run(ClientRepository $clients)
5555
]);
5656

5757
// Create client so we can generate tokens
58-
$clients->createPersonalAccessGrantClient('PmApi');
58+
$personalAccessClient = $clients->createPersonalAccessGrantClient('PmApi');
59+
$personalAccessClient->save();
5960

6061
// Create client OAuth (for 3-legged auth) - Authorization Code Grant for Swagger UI
6162
$clients->createAuthorizationCodeGrantClient(

0 commit comments

Comments
 (0)