-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.go
35 lines (31 loc) · 943 Bytes
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package sdk
import (
"github.com/clawio/clawiod/codes"
"github.com/clawio/clawiod/services/authentication"
)
type (
// AuthService is the interface that deals with the calls to an authentication authentication.
AuthService interface {
Token(username, password string) (string, *codes.Response, error)
}
authService struct {
client *client
baseURL string
}
)
// Token gets an access token after authenticating the user with username and password.
func (s *authService) Token(username, password string) (string, *codes.Response, error) {
tokenRequest := &authentication.TokenRequest{
Username: username,
Password: password}
req, err := s.client.newRequest("POST", "token", tokenRequest)
if err != nil {
return "", nil, err
}
tokenResponse := &authentication.TokenResponse{}
resp, err := s.client.do(req, tokenResponse, true)
if err != nil {
return "", resp, err
}
return tokenResponse.AccessToken, resp, nil
}