Skip to content

Commit

Permalink
Support login key URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
wolveix committed Mar 25, 2024
1 parent 63b7793 commit 5ba1208
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
46 changes: 39 additions & 7 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,47 @@ import (
"time"
)

type credentials struct {
username string
passkey string
type (
credentials struct {
username string
passkey string
}

LoginHistory struct {
Attempts int `json:"attempts"`
Host string `json:"host"`
Timestamp time.Time `json:"timestamp"`
}

LoginKeyURL struct {
AllowNetworks []string `json:"allowNetworks"`
Created time.Time `json:"created"`
CreatedBy string `json:"createdBy"`
Expires time.Time `json:"expires"`
Id string `json:"id"`
RedirectURL string `json:"redirectURL"`
URL string `json:"url"`
}
)

func (c *UserContext) CreateLoginURL(loginKeyURL *LoginKeyURL) (*LoginKeyURL, error) {
var response LoginKeyURL

if _, err := c.api.makeRequestN(http.MethodPost, "login-keys/urls", c.credentials, loginKeyURL, &response); err != nil {
return nil, fmt.Errorf("failed to create login URL: %v", err)
}

return &response, nil
}

type LoginHistory struct {
Attempts int `json:"attempts"`
Host string `json:"host"`
Timestamp time.Time `json:"timestamp"`
func (c *UserContext) GetLoginURLs() ([]*LoginKeyURL, error) {
var loginKeyURLs []*LoginKeyURL

if _, err := c.api.makeRequestN(http.MethodGet, "login-keys/urls", c.credentials, nil, &loginKeyURLs); err != nil {
return nil, fmt.Errorf("failed to get login URLs: %v", err)
}

return loginKeyURLs, nil
}

func (c *AdminContext) GetLoginHistory() ([]*LoginHistory, error) {
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
Expand Down

0 comments on commit 5ba1208

Please sign in to comment.