Skip to content

Commit a12e85c

Browse files
committed
Added token login support
Sets the password as the token, if the username is empty. This way one can login using an api token.
1 parent 4ed7e12 commit a12e85c

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

phpipam/client/client.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ func NewClient(s *session.Session) *Client {
2929
// loginSession logs in a session via the user controller. This is the only
3030
// valid operation if the session does not have a token yet.
3131
func loginSession(s *session.Session) error {
32-
var out session.Token
33-
r := request.NewRequest(s)
34-
r.Method = "POST"
35-
r.URI = "/user/"
36-
r.Input = &struct{}{}
37-
r.Output = &out
38-
if err := r.Send(); err != nil {
39-
return err
40-
}
41-
s.Token = out
32+
if s.Config.Username == "" {
33+
s.Token.String = s.Config.Password
34+
} else {
35+
var out session.Token
36+
r := request.NewRequest(s)
37+
r.Method = "POST"
38+
r.URI = "/user/"
39+
r.Input = &struct{}{}
40+
r.Output = &out
41+
if err := r.Send(); err != nil {
42+
return err
43+
}
44+
s.Token = out
45+
}
4246
return nil
4347
}
4448

0 commit comments

Comments
 (0)