Skip to content

Commit

Permalink
Merge pull request Telmate#373 from camaeel/feat/ticket-login
Browse files Browse the repository at this point in the history
feat: client initialized with ticket and CSRF prevention Token
  • Loading branch information
Tinyblargon authored Nov 24, 2024
2 parents 222002b + ea0560e commit ea532c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions proxmox/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ 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`
//
// Docs: https://pve.proxmox.com/wiki/Proxmox_VE_API#Authentication
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
Expand Down
5 changes: 5 additions & 0 deletions proxmox/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down

0 comments on commit ea532c4

Please sign in to comment.