[unifi] Fixed 404 error with reconnect and no default value set for UniFiOS Checkbox (#11004)
* Fixed 404 error by obtaining Csrf token before login Signed-off-by: Mathias Maes <watcherwhale@maes.family> * Only try to obtain a csrf token when using UniFi OS Signed-off-by: Mathias Maes <watcherwhale@maes.family> * Updated documentation Signed-off-by: Mathias Maes <watcherwhale@maes.family> * Updated thing configuration in README.md Signed-off-by: Mathias Maes <watcherwhale@maes.family>
This commit is contained in:
@@ -94,6 +94,10 @@ public class UniFiController {
|
||||
// Public API
|
||||
|
||||
public void start() throws UniFiException {
|
||||
if (unifios) {
|
||||
obtainCsrfToken();
|
||||
}
|
||||
|
||||
login();
|
||||
}
|
||||
|
||||
@@ -101,9 +105,15 @@ public class UniFiController {
|
||||
logout();
|
||||
}
|
||||
|
||||
public void login() throws UniFiException {
|
||||
public void obtainCsrfToken() throws UniFiException {
|
||||
csrfToken = "";
|
||||
|
||||
UniFiControllerRequest<Void> req = newRequest(Void.class);
|
||||
req.setPath("/");
|
||||
executeRequest(req);
|
||||
}
|
||||
|
||||
public void login() throws UniFiException {
|
||||
UniFiControllerRequest<Void> req = newRequest(Void.class);
|
||||
req.setPath(unifios ? "/api/auth/login" : "/api/login");
|
||||
req.setBodyParameter("username", username);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<parameter name="unifios" type="boolean" required="true">
|
||||
<label>UniFi OS</label>
|
||||
<description>If the UniFi Controller is running on UniFi OS.</description>
|
||||
<default>false</default>
|
||||
</parameter>
|
||||
<parameter name="username" type="text" required="true">
|
||||
<label>Username</label>
|
||||
|
||||
Reference in New Issue
Block a user