diff --git a/ProcessMaker/Providers/ProcessMakerServiceProvider.php b/ProcessMaker/Providers/ProcessMakerServiceProvider.php index 56d38de1d3..c19ded9d5f 100644 --- a/ProcessMaker/Providers/ProcessMakerServiceProvider.php +++ b/ProcessMaker/Providers/ProcessMakerServiceProvider.php @@ -23,6 +23,7 @@ use Laravel\Horizon\Horizon; use Laravel\Horizon\SystemProcessCounter; use Laravel\Horizon\WorkerCommandString; +use Laravel\Passport\Client as PassportClient; use Lavary\Menu\Menu; use OpenApi\Analysers\AttributeAnnotationFactory; use OpenApi\Analysers\DocBlockAnnotationFactory; @@ -354,6 +355,24 @@ protected static function bootObservers(): void Models\ProcessRequestToken::observe(Observers\ProcessRequestTokenObserver::class); Models\ProcessCollaboration::observe(Observers\ProcessCollaborationObserver::class); + + // Due to this change https://github.com/laravel/passport/blob/ea020190123953426a439f0267c6cfa478f6e6e7/src/Guards/TokenGuard.php#L146 + // user ID is now required for bearer tokens clients. Any user will work here, the token itself + // is what's associated with the real user. For now, we'll use the first administrator user. + PassportClient::creating(function (PassportClient $client): void { + if (!$client->personal_access_client || $client->user_id !== null) { + return; + } + + $adminUserId = Models\User::query() + ->where('is_administrator', true) + ->orderBy('id') + ->value('id'); + + if ($adminUserId !== null) { + $client->user_id = $adminUserId; + } + }); } /** diff --git a/upgrades/2026_05_07_212653_set_user_id_on_oauth_client.php b/upgrades/2026_05_07_212653_set_user_id_on_oauth_client.php new file mode 100644 index 0000000000..2b9f183677 --- /dev/null +++ b/upgrades/2026_05_07_212653_set_user_id_on_oauth_client.php @@ -0,0 +1,71 @@ +where('is_administrator', true) + ->orderBy('id') + ->value('id'); + + if ($adminUserId === null) { + return; + } + + DB::table('oauth_clients') + ->where('personal_access_client', true) + ->whereNull('user_id') + ->update(['user_id' => $adminUserId]); + } + + /** + * Reverse the upgrade migration. + * + * @return void + */ + public function down() + { + $adminUserId = DB::table('users') + ->where('is_administrator', true) + ->orderBy('id') + ->value('id'); + + if ($adminUserId === null) { + return; + } + + DB::table('oauth_clients') + ->where('personal_access_client', true) + ->where('user_id', $adminUserId) + ->update(['user_id' => null]); + } +}