Skip to content

Commit 22f3f23

Browse files
committed
fix: handling of unavailable uids
Signed-off-by: Jana Peper <[email protected]>
1 parent 01c6dca commit 22f3f23

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

apps/webhook_listeners/lib/BackgroundJobs/WebhookCall.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ protected function run($argument): void {
4747

4848
// adding temporary auth tokens to the call
4949
$data['tokens'] = $this->tokenService->getTokens($webhookListener, $data['user']['uid']);
50+
error_log(json_encode($data['tokens']));
5051
$options = [
5152
'verify' => $this->certificateManager->getAbsoluteBundlePath(),
5253
'headers' => $webhookListener->getHeaders() ?? [],

apps/webhook_listeners/lib/Service/TokenService.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,30 @@ public function getTokens(WebhookListener $webhookListener, ?string $triggerUser
3838
$tokenNeeded = $webhookListener->getTokenNeeded();
3939
if (isset($tokenNeeded['users'])) {
4040
foreach ($tokenNeeded['users'] as $userId) {
41-
$tokens['users'][$userId] = $webhookListener->createTemporaryToken($userId);
41+
$tokens['users'][$userId] = $this->createTemporaryToken($userId);
4242
}
4343
}
4444
if (isset($tokenNeeded['users'])) {
45+
error_log(json_encode($tokenNeeded));
4546
foreach ($tokenNeeded['functions'] as $function) {
4647
switch ($function) {
4748
case 'owner':
4849
// token for the person who created the flow
4950
$functionId = $webhookListener->getUserId();
51+
if (is_null($functionId)) { // no owner uid available
52+
break;
53+
}
5054
$tokens['functions']['owner'] = [
51-
$functionId => $webhookListener->createTemporaryToken($functionId)
55+
$functionId => $this->createTemporaryToken($functionId)
5256
];
5357
break;
5458
case 'trigger':
5559
// token for the person who triggered the webhook
60+
if (is_null($triggerUserId)) { // no trigger uid available
61+
break;
62+
}
5663
$tokens['functions']['trigger'] = [
57-
$triggerUserId => $webhookListener->createTemporaryToken($triggerUserId)
64+
$triggerUserId => $this->createTemporaryToken($triggerUserId)
5865
];
5966
break;
6067
}
@@ -65,7 +72,7 @@ public function getTokens(WebhookListener $webhookListener, ?string $triggerUser
6572
}
6673

6774

68-
public function createTemporaryToken(string $userId): string {
75+
private function createTemporaryToken(string $userId): string {
6976
$token = $this->generateRandomDeviceToken();
7077
$name = 'Ephemeral webhook authentication';
7178
$password = null;

0 commit comments

Comments
 (0)