]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
adapt auth utils for proxmox token authentication
authorTim Marx <t.marx@proxmox.com>
Thu, 7 May 2020 12:28:24 +0000 (14:28 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 30 Jun 2020 11:25:14 +0000 (13:25 +0200)
Signed-off-by: Tim Marx <t.marx@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/Utils.js

index d959dee3844c72887d86e194ef45c6afb052ee20..d2ad7a149800a1b013ad418fbb102659caee63c8 100644 (file)
@@ -39,6 +39,10 @@ Ext.Ajax.on('beforerequest', function(conn, options) {
        }
        options.headers.CSRFPreventionToken = Proxmox.CSRFPreventionToken;
     }
+    let storedUser = Proxmox.Utils.getStoredUser();
+    if (storedUser.token) {
+       options.headers.Authorization = storedUser.token;
+    }
 });
 
 Ext.define('Proxmox.Utils', { // a singleton
@@ -238,22 +242,34 @@ utilities: {
        return min < width ? width : min;
     },
 
+    getStoredAuth: function() {
+       let storedAuth = JSON.parse(window.localStorage.getItem('ProxmoxUser'));
+       return storedAuth || {};
+    },
+
     setAuthData: function(data) {
-       Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
        Proxmox.UserName = data.username;
        Proxmox.LoggedOut = data.LoggedOut;
        // creates a session cookie (expire = null)
        // that way the cookie gets deleted after the browser window is closed
-       Ext.util.Cookies.set(Proxmox.Setup.auth_cookie_name, data.ticket, null, '/', null, true);
+       if (data.ticket) {
+           Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
+           Ext.util.Cookies.set(Proxmox.Setup.auth_cookie_name, data.ticket, null, '/', null, true);
+       }
+
+       if (data.token) {
+           window.localStorage.setItem('ProxmoxUser', JSON.stringify(data));
+       }
     },
 
     authOK: function() {
        if (Proxmox.LoggedOut) {
            return undefined;
        }
+       let storedAuth = Proxmox.Utils.getStoredUser();
        let cookie = Ext.util.Cookies.get(Proxmox.Setup.auth_cookie_name);
-       if (Proxmox.UserName !== '' && cookie && !cookie.startsWith("PVE:tfa!")) {
-           return cookie;
+       if ((Proxmox.UserName !== '' && cookie && !cookie.startsWith("PVE:tfa!")) || storedAuth.token) {
+           return cookie || storedAuth.token;
        } else {
            return false;
        }
@@ -264,6 +280,7 @@ utilities: {
            return;
        }
        Ext.util.Cookies.clear(Proxmox.Setup.auth_cookie_name);
+       window.localStorage.removeItem("ProxmoxUser");
     },
 
     // comp.setLoading() is buggy in ExtJS 4.0.7, so we