From d36a088101e3422e98be1c042afdebaf5f190e8b Mon Sep 17 00:00:00 2001 From: malle-pietje Date: Tue, 27 Feb 2024 18:48:41 +0100 Subject: [PATCH] API client class v1.1.90 - remove existing x-csrf-token headers before adding a new one, UniFi OS does not like multiple x-csrf-tokens in the same request --- src/Client.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 277a9ac..a6cc64d 100755 --- a/src/Client.php +++ b/src/Client.php @@ -13,7 +13,7 @@ * * @package UniFi_Controller_API_Client_Class * @author Art of WiFi - * @version Release: 1.1.89 + * @version Release: 1.1.90 * @license This class is subject to the MIT license that is bundled with this package in the file LICENSE.md * @example This directory in the package repository contains a collection of examples: * https://github.com/Art-of-WiFi/UniFi-API-client/tree/master/examples @@ -25,7 +25,7 @@ class Client * * NOTE: do **not** modify the values below, instead use the constructor or the getter and setter functions/methods */ - const CLASS_VERSION = '1.1.89'; + const CLASS_VERSION = '1.1.90'; protected string $baseurl = 'https://127.0.0.1:8443'; protected string $user = ''; protected string $password = ''; @@ -4108,6 +4108,15 @@ protected function create_x_csrf_token_header() return; } + /** + * remove any existing x-csrf-token headers first + */ + foreach ($this->curl_headers as $index => $header) { + if (strpos(strtolower($header), strtolower('x-csrf-token:')) !== false) { + unset($this->curl_headers[$index]); + } + } + $this->curl_headers[] = 'x-csrf-token: ' . json_decode(base64_decode($jwt_components[1]))->csrfToken; } }