Skip to content

Commit

Permalink
fix: preserve original Authentication to be swapped later in HaProxy
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
  • Loading branch information
andrey18106 committed Jul 22, 2024
1 parent aed1e83 commit 8698204
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private function prepareRequestToExApp(
}

if (isset($options['headers']) && is_array($options['headers'])) {
$options['headers'] = [...$options['headers'], ...$this->commonService->buildAppAPIAuthHeaders($request, $userId, $exApp->getAppid(), $exApp->getVersion(), $exApp->getSecret())];
$options['headers'] = [...$this->swapAuthenticationHeader($options['headers']), ...$this->commonService->buildAppAPIAuthHeaders($request, $userId, $exApp->getAppid(), $exApp->getVersion(), $exApp->getSecret())];
} else {
$options['headers'] = $this->commonService->buildAppAPIAuthHeaders($request, $userId, $exApp->getAppid(), $exApp->getVersion(), $exApp->getSecret());
}
Expand Down Expand Up @@ -207,7 +207,7 @@ private function prepareRequestToExApp2(
}

if (isset($options['headers']) && is_array($options['headers'])) {
$options['headers'] = [...$options['headers'], ...$this->commonService->buildAppAPIAuthHeaders($request, $userId, $exApp->getAppid(), $exApp->getVersion(), $exApp->getSecret())];
$options['headers'] = [...$this->swapAuthenticationHeader($options['headers']), ...$this->commonService->buildAppAPIAuthHeaders($request, $userId, $exApp->getAppid(), $exApp->getVersion(), $exApp->getSecret())];
} else {
$options['headers'] = $this->commonService->buildAppAPIAuthHeaders($request, $userId, $exApp->getAppid(), $exApp->getVersion(), $exApp->getSecret());
}
Expand Down Expand Up @@ -237,6 +237,21 @@ private function prepareRequestToExApp2(
return ['url' => $url, 'options' => $options];
}

/**
* This is required for AppAPI Docker Socket Proxy, as the Basic Auth is already in use by HaProxy,
* and the incoming request's Authentication is replaced with X-Original-Authentication header
* after HaProxy authenticated.
*
* @since AppAPI 3.0.0
*/
private function swapAuthenticationHeader(array $headers): array {
// Swap Basic auth header Authentication to X-Original-Authentication
if (isset($headers['Authorization'])) {
$headers['X-Original-Authentication'] = $headers['Authorization'];
}
return $headers;
}

private function getUriEncodedParams(array $params): string {
$paramsContent = '';
foreach ($params as $key => $value) {
Expand Down

0 comments on commit 8698204

Please sign in to comment.