mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-08-06 23:32:45 +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
23
src/Utils.js
23
src/Utils.js
@ -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
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user