Skip to content

Commit 39bf43a

Browse files
authored
add AppAPI auth to init endpoint request (#111)
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
1 parent e6bd36b commit 39bf43a

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/Service/AppAPIService.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,9 @@ public function dispatchExAppInit(ExApp $exApp): void {
416416
) . '/init';
417417

418418
$options = [
419-
'headers' => [
420-
'Accept' => 'application/json',
421-
'Content-Type' => 'application/json',
422-
],
419+
'Accept' => 'application/json',
420+
'Content-Type' => 'application/json',
421+
'headers' => $this->buildAppAPIAuthHeaders(null, null, $exApp),
423422
'nextcloud' => [
424423
'allow_local_address' => true,
425424
],
@@ -560,13 +559,7 @@ public function requestToExApp(
560559
$exApp->getPort()) . $route;
561560

562561
$options = [
563-
'headers' => [
564-
'AA-VERSION' => $this->appManager->getAppVersion(Application::APP_ID, false),
565-
'EX-APP-ID' => $exApp->getAppid(),
566-
'EX-APP-VERSION' => $exApp->getVersion(),
567-
'AUTHORIZATION-APP-API' => base64_encode($userId . ':' . $exApp->getSecret()),
568-
'AA-REQUEST-ID' => $request instanceof IRequest ? $request->getId() : 'CLI',
569-
],
562+
'headers' => $this->buildAppAPIAuthHeaders($request, $userId, $exApp),
570563
'nextcloud' => [
571564
'allow_local_address' => true, // it's required as we are using ExApp appid as hostname (usually local)
572565
],
@@ -603,6 +596,16 @@ public function requestToExApp(
603596
}
604597
}
605598

599+
private function buildAppAPIAuthHeaders(?IRequest $request, ?string $userId, ExApp $exApp): array {
600+
return [
601+
'AA-VERSION' => $this->appManager->getAppVersion(Application::APP_ID, false),
602+
'EX-APP-ID' => $exApp->getAppid(),
603+
'EX-APP-VERSION' => $exApp->getVersion(),
604+
'AUTHORIZATION-APP-API' => base64_encode($userId . ':' . $exApp->getSecret()),
605+
'AA-REQUEST-ID' => $request instanceof IRequest ? $request->getId() : 'CLI',
606+
];
607+
}
608+
606609
/**
607610
* @param string $protocol
608611
* @param string $host

0 commit comments

Comments
 (0)