I am currently developing an integrated web application for Proxmox. The frontend is built with Angular, and the backend uses Node.js with Express. After deploying the application using Docker and testing the noVNC connection, I consistently encounter a 401 error. Below is the relevant
code:
Express:
Angular:
Despite setting the PVEAuthCookie and CSRFPreventionToken, the connection fails with a 401 error. Interestingly, when I manually navigate to the Proxmox URL in the same browser session, the connection works without issues.
I would greatly appreciate any guidance on how to resolve this issue. Thank you!
code:
Express:
Code:
app.post('/express/api/vnc-console', (req, res) => {
const { node, vmid } = req.body;
if (!node || !vmid) {
return res.status(400).send({ error: 'Node and VM ID are required' });
}
// Login to Proxmox
loginToProxmox((err, loginData) => {
if (err) {
console.error('Login error:', err);
return res.status(500).send({ error: 'Failed to login to Proxmox' });
}
const { ticket, CSRFPreventionToken } = loginData;
res.send({
ticket,
CSRFPreventionToken,
});
});
});
Angular:
Code:
this.proxmoxService.getVncUrl('ttc', 'test').subscribe({
next: (response: any) => {
const ticket = response.ticket;
const csrfToken = response.CSRFPreventionToken;
// Generate Proxmox URL
this.proxmoxUrl = `https://192.168.32.99:8006/?console=kvm&novnc=1&vmid=2002&vmname=DMZ-DB-Server&node=testServer&resize=off&cmd=`;
document.cookie = `PVEAuthCookie=${ticket}`;
const headers = new HttpHeaders({
'PVEAuthCookie': ticket,
'CSRFPreventionToken': csrfToken,
});
this.http.post(`${this.proxmoxUrl}`, {}, {
headers,
withCredentials: true,
}).subscribe({
next: (res) => {
const iframe = document.getElementById('vncFrame') as HTMLIFrameElement;
iframe.src = this.proxmoxUrl;
},
error: (err) => {
console.error('Error during connection:', err);
},
});
},
error: (error) => {
console.error('Failed to get VNC URL:', error);
},
});
Despite setting the PVEAuthCookie and CSRFPreventionToken, the connection fails with a 401 error. Interestingly, when I manually navigate to the Proxmox URL in the same browser session, the connection works without issues.
I would greatly appreciate any guidance on how to resolve this issue. Thank you!
Last edited: