Skip to content

Commit 16b5446

Browse files
committed
Fix DevLink
1 parent 873d698 commit 16b5446

3 files changed

Lines changed: 67 additions & 8 deletions

File tree

ProcessMaker/Http/Controllers/Admin/DevLinkController.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,24 @@ public function getOauthClient(Request $request)
3636
$devLinkId = $request->input('devlink_id');
3737
$redirectUri = $request->input('redirect_uri');
3838

39-
$client = Client::where([
39+
// We can't re-use a client because the secret is hashed.
40+
Client::where([
4041
'name' => 'devlink',
4142
'redirect' => $redirectUri,
42-
])->first();
43+
])
44+
->get()
45+
->each(function ($c) {
46+
$c->delete();
47+
});
4348

44-
if (!$client) {
45-
$clientRepository = app('Laravel\Passport\ClientRepository');
46-
$client = $clientRepository->createAuthorizationCodeGrantClient('devlink', [$redirectUri]);
47-
}
49+
$clientRepository = app('Laravel\Passport\ClientRepository');
50+
$client = $clientRepository->createAuthorizationCodeGrantClient('devlink', [$redirectUri]);
51+
$plainSecret = $client->plainSecret;
4852

4953
$query = http_build_query([
5054
'devlink_id' => $devLinkId,
5155
'client_id' => $client->id,
52-
'client_secret' => $client->secret,
56+
'client_secret' => $plainSecret,
5357
]);
5458

5559
return redirect($redirectUri . '?' . $query);

tests/Feature/Admin/DevLinkTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,16 @@ public function testGetOauthClient()
8383
$response = $this->webCall('GET', $url);
8484

8585
$response->assertStatus(302);
86+
$locationHeader = $response->headers->get('Location');
87+
$queryString = parse_url($locationHeader, PHP_URL_QUERY);
88+
parse_str($queryString, $queryParams);
89+
$clientSecretQueryParam = $queryParams['client_secret'] ?? '';
8690

8791
$lastCreatedClient = Client::orderBy('id', 'desc')->first();
8892
$expectedParams = [
8993
'devlink_id' => $devLink->id,
9094
'client_id' => $lastCreatedClient->id,
91-
'client_secret' => $lastCreatedClient->secret,
95+
'client_secret' => $clientSecretQueryParam,
9296
];
9397
$response->assertRedirect(route('devlink.index', $expectedParams));
9498
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Artisan;
4+
use ProcessMaker\Upgrades\UpgradeMigration as Upgrade;
5+
6+
class EncryptClientSecrets extends Upgrade
7+
{
8+
/**
9+
* Run any validations/pre-run checks to ensure the environment, settings,
10+
* packages installed, etc. are right correct to run this upgrade.
11+
*
12+
* Throw a \RuntimeException if the conditions are *NOT* correct for this
13+
* upgrade migration to run. If this is not a required upgrade, then it
14+
* will be skipped. Otherwise the exception thrown will be caught, noted,
15+
* and will prevent the remaining migrations from continuing to run.
16+
*
17+
* Returning void or null denotes the checks were successful.
18+
*
19+
* @return void
20+
*
21+
* @throws RuntimeException
22+
*/
23+
public function preflightChecks()
24+
{
25+
//
26+
}
27+
28+
/**
29+
* Run the upgrade migration.
30+
*
31+
* @return void
32+
*/
33+
public function up()
34+
{
35+
Artisan::call('passport:hash', ['--force' => true]);
36+
$output = Artisan::output();
37+
if (!str_contains($output, 'All client secrets were successfully hashed')) {
38+
throw new RuntimeException('Failed to hash client secrets. Output: ' . $output);
39+
}
40+
}
41+
42+
/**
43+
* Reverse the upgrade migration.
44+
*
45+
* @return void
46+
*/
47+
public function down()
48+
{
49+
//
50+
}
51+
}

0 commit comments

Comments
 (0)