Skip to content

Commit

Permalink
API client class v1.1.83
Browse files Browse the repository at this point in the history
- added a 'accept: application/json' header to the login requests
- re-added support for cookies when working with a UniFi OS-based controller
  • Loading branch information
malle-pietje committed Dec 18, 2023
1 parent 7fe7a40 commit 2970f79
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @package UniFi_Controller_API_Client_Class
* @author Art of WiFi <info@artofwifi.net>
* @version Release: 1.1.82
* @version Release: 1.1.83
* @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
Expand All @@ -25,7 +25,7 @@ class Client
*
* NOTE: do **not** modify the values here, instead use the constructor or the getter and setter functions/methods
*/
const CLASS_VERSION = '1.1.82';
const CLASS_VERSION = '1.1.83';
protected $baseurl = 'https://127.0.0.1:8443';
protected $user = '';
protected $password = '';
Expand Down Expand Up @@ -101,7 +101,7 @@ public function __destruct()
/**
* if $_SESSION['unificookie'] is set, do not log out here except when this is a UniFi OS-based controller
*/
if (isset($_SESSION['unificookie']) && !$this->is_unifi_os) {
if (isset($_SESSION['unificookie'])) {
return;
}

Expand Down Expand Up @@ -161,6 +161,7 @@ public function login()
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(['username' => $this->user, 'password' => $this->password]),
CURLOPT_HTTPHEADER => [
'accept: application/json',
'content-type: application/json',
'Expect:',
],
Expand Down Expand Up @@ -247,6 +248,7 @@ public function logout()
];

$logout_path = '/logout';

if ($this->is_unifi_os) {
$logout_path = '/api/auth/logout';
$curl_options[CURLOPT_CUSTOMREQUEST] = 'POST';
Expand Down Expand Up @@ -3952,6 +3954,7 @@ protected function exec_curl($path, $payload = null)
* add empty Expect header to prevent cURL from injecting an "Expect: 100-continue" header
*/
$this->curl_headers = [
'accept: application/json',
'content-type: application/json',
'Expect:',
];
Expand Down

0 comments on commit 2970f79

Please sign in to comment.