From d7aadc3f2c66217458a906c71bd62cf3e0844a89 Mon Sep 17 00:00:00 2001 From: camaeel <12999736+camaeel@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:12:00 +0100 Subject: [PATCH 1/3] feat: client intialized with ticket and CSRF prevention Token --- proxmox/client.go | 4 ++++ proxmox/session.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/proxmox/client.go b/proxmox/client.go index 6fb156d8..9b2fb193 100644 --- a/proxmox/client.go +++ b/proxmox/client.go @@ -131,6 +131,10 @@ func (c *Client) SetAPIToken(userID, token string) { c.session.SetAPIToken(userID, token) } +func (c *Client) SetTicket(ticket, csrfPreventionToken string) { + c.session.SetTicket(ticket, csrfPreventionToken) +} + func (c *Client) Login(username string, password string, otp string) (err error) { c.Username = username c.Password = password diff --git a/proxmox/session.go b/proxmox/session.go index 5cf39203..2a084989 100644 --- a/proxmox/session.go +++ b/proxmox/session.go @@ -167,6 +167,11 @@ func (s *Session) SetAPIToken(userID, token string) { s.AuthToken = auth } +func (s *Session) SetTicket(ticket, csrfPreventionToken string) { + s.AuthTicket = ticket + s.CsrfToken = csrfPreventionToken +} + func (s *Session) Login(username string, password string, otp string) (err error) { reqUser := map[string]interface{}{"username": username, "password": password} if otp != "" { From 8eee42e992d6fef1b180de88992e75777f82f520 Mon Sep 17 00:00:00 2001 From: camaeel <12999736+camaeel@users.noreply.github.com> Date: Sun, 24 Nov 2024 00:13:24 +0100 Subject: [PATCH 2/3] docs: add ticket --- proxmox/client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/proxmox/client.go b/proxmox/client.go index 9b2fb193..49f8389d 100644 --- a/proxmox/client.go +++ b/proxmox/client.go @@ -131,6 +131,12 @@ func (c *Client) SetAPIToken(userID, token string) { c.session.SetAPIToken(userID, token) } +// SetTicket let's set directly ticket and csrfPreventionToken obtained in +// a different way, for example using OIDC identity provider +// +// Parameters: +// - `ticket` +// - `csrfPreventionToken` func (c *Client) SetTicket(ticket, csrfPreventionToken string) { c.session.SetTicket(ticket, csrfPreventionToken) } From ea0560e7d5688e973cabff2373799aad860e7874 Mon Sep 17 00:00:00 2001 From: camaeel <12999736+camaeel@users.noreply.github.com> Date: Sun, 24 Nov 2024 00:23:02 +0100 Subject: [PATCH 3/3] make (Session)setTicket private --- proxmox/client.go | 4 +++- proxmox/session.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/proxmox/client.go b/proxmox/client.go index 49f8389d..b26c1940 100644 --- a/proxmox/client.go +++ b/proxmox/client.go @@ -137,8 +137,10 @@ func (c *Client) SetAPIToken(userID, token string) { // Parameters: // - `ticket` // - `csrfPreventionToken` +// +// Docs: https://pve.proxmox.com/wiki/Proxmox_VE_API#Authentication func (c *Client) SetTicket(ticket, csrfPreventionToken string) { - c.session.SetTicket(ticket, csrfPreventionToken) + c.session.setTicket(ticket, csrfPreventionToken) } func (c *Client) Login(username string, password string, otp string) (err error) { diff --git a/proxmox/session.go b/proxmox/session.go index 2a084989..e5667194 100644 --- a/proxmox/session.go +++ b/proxmox/session.go @@ -167,7 +167,7 @@ func (s *Session) SetAPIToken(userID, token string) { s.AuthToken = auth } -func (s *Session) SetTicket(ticket, csrfPreventionToken string) { +func (s *Session) setTicket(ticket, csrfPreventionToken string) { s.AuthTicket = ticket s.CsrfToken = csrfPreventionToken }