mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-08-07 06:31:34 +00:00
adapt auth utils for proxmox token authentication
Signed-off-by: Tim Marx <t.marx@proxmox.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
bde489e51c
commit
63252ab6ab
25
src/Utils.js
25
src/Utils.js
@ -39,6 +39,10 @@ Ext.Ajax.on('beforerequest', function(conn, options) {
|
|||||||
}
|
}
|
||||||
options.headers.CSRFPreventionToken = Proxmox.CSRFPreventionToken;
|
options.headers.CSRFPreventionToken = Proxmox.CSRFPreventionToken;
|
||||||
}
|
}
|
||||||
|
let storedUser = Proxmox.Utils.getStoredUser();
|
||||||
|
if (storedUser.token) {
|
||||||
|
options.headers.Authorization = storedUser.token;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ext.define('Proxmox.Utils', { // a singleton
|
Ext.define('Proxmox.Utils', { // a singleton
|
||||||
@ -238,22 +242,34 @@ utilities: {
|
|||||||
return min < width ? width : min;
|
return min < width ? width : min;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getStoredAuth: function() {
|
||||||
|
let storedAuth = JSON.parse(window.localStorage.getItem('ProxmoxUser'));
|
||||||
|
return storedAuth || {};
|
||||||
|
},
|
||||||
|
|
||||||
setAuthData: function(data) {
|
setAuthData: function(data) {
|
||||||
Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
|
|
||||||
Proxmox.UserName = data.username;
|
Proxmox.UserName = data.username;
|
||||||
Proxmox.LoggedOut = data.LoggedOut;
|
Proxmox.LoggedOut = data.LoggedOut;
|
||||||
// creates a session cookie (expire = null)
|
// creates a session cookie (expire = null)
|
||||||
// that way the cookie gets deleted after the browser window is closed
|
// 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() {
|
authOK: function() {
|
||||||
if (Proxmox.LoggedOut) {
|
if (Proxmox.LoggedOut) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
let storedAuth = Proxmox.Utils.getStoredUser();
|
||||||
let cookie = Ext.util.Cookies.get(Proxmox.Setup.auth_cookie_name);
|
let cookie = Ext.util.Cookies.get(Proxmox.Setup.auth_cookie_name);
|
||||||
if (Proxmox.UserName !== '' && cookie && !cookie.startsWith("PVE:tfa!")) {
|
if ((Proxmox.UserName !== '' && cookie && !cookie.startsWith("PVE:tfa!")) || storedAuth.token) {
|
||||||
return cookie;
|
return cookie || storedAuth.token;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -264,6 +280,7 @@ utilities: {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Ext.util.Cookies.clear(Proxmox.Setup.auth_cookie_name);
|
Ext.util.Cookies.clear(Proxmox.Setup.auth_cookie_name);
|
||||||
|
window.localStorage.removeItem("ProxmoxUser");
|
||||||
},
|
},
|
||||||
|
|
||||||
// comp.setLoading() is buggy in ExtJS 4.0.7, so we
|
// comp.setLoading() is buggy in ExtJS 4.0.7, so we
|
||||||
|
Loading…
Reference in New Issue
Block a user