Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: client intialized with ticket and CSRF prevention Token #373

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment to this?
Just a notice that it is different from the normal login/api authentication methods and what it is used for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

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
Loading