Config is proper, auth logic OK, update readme

This commit is contained in:
Christopher Vagnetoft
2026-01-17 17:53:16 +01:00
parent 278c9d8d68
commit b5de63e225
4 changed files with 99 additions and 9 deletions

View File

@@ -174,13 +174,20 @@ class NtfiDaemon
$serverInfo = $this->servers[$connection] ?? throw new \Exception("The server '{$connection}' is not configured");
$browser = new Browser();
if (isset($serverInfo['token']) && $serverInfo['token']) {
$browser = new Browser();
$browser->withHeader("authorization", "Bearer {$serverInfo['token']}");
$browser = $browser
->withHeader("authorization", "Bearer {$serverInfo['token']}");
} elseif (isset($serverInfo['username']) && $serverInfo['username'] &&
isset($serverInfo['password']) && $serverInfo['password']) {
$auth = base64_encode(sprintf("%s:%s", $serverInfo['username'], $serverInfo['password']));
$browser = $browser
->withHeader("authorization", "Basic {$auth}");
}
$url = sprintf("https://%s/%s", $serverInfo['server'], $topic);
printf("post: %s\n", $url);
$browser->post($url, [
'content-type' => $type,
], $body)->then(