psu/client/auth.go
2019-08-26 09:11:17 -04:00

39 lines
883 B
Go

package client
import "net/http"
// AuthenticateUserOptions represents options passed to PortainerClient.AuthenticateUser()
type AuthenticateUserOptions struct {
Username string
Password string
}
// AuthenticateUserRequest represents the body of a request to POST /auth
type AuthenticateUserRequest struct {
Username string
Password string
}
// AuthenticateUserResponse represents the body of a response for a request to POST /auth
type AuthenticateUserResponse struct {
Jwt string
}
func (n *portainerClientImp) AuthenticateUser(options AuthenticateUserOptions) (token string, err error) {
reqBody := AuthenticateUserRequest{
Username: options.Username,
Password: options.Password,
}
respBody := AuthenticateUserResponse{}
err = n.doJSON("auth", http.MethodPost, http.Header{}, &reqBody, &respBody)
if err != nil {
return
}
token = respBody.Jwt
return
}