-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
authentication.go
47 lines (40 loc) · 1.25 KB
/
authentication.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
36
37
38
39
40
41
42
43
44
45
46
47
package cachet
const (
// HTTP Basic Authentication
authTypeBasic = 1
// Auth by API token
authTypeToken = 2
)
// AuthenticationService contains contains Authentication related functions.
type AuthenticationService struct {
client *Client
username string
secret string
authType int
}
// SetBasicAuth sets basic parameters for HTTP Basic auth.
// Attention! Basic Auth is no longer supported by Cachet since ~v2.1.
// You can only use this if you running an older version.
// Checkout https://github.com/CachetHQ/Cachet/issues/1658
func (s *AuthenticationService) SetBasicAuth(username, password string) {
s.username = username
s.secret = password
s.authType = authTypeBasic
}
// SetTokenAuth sets the API token for "token auth"
func (s *AuthenticationService) SetTokenAuth(token string) {
s.secret = token
s.authType = authTypeToken
}
// HasAuth checks if an auth type is used
func (s *AuthenticationService) HasAuth() bool {
return s.authType > 0
}
// HasBasicAuth checks if the auth type is HTTP Basic auth
func (s *AuthenticationService) HasBasicAuth() bool {
return s.authType == authTypeBasic
}
// HasTokenAuth checks we auth with an API token against the API
func (s *AuthenticationService) HasTokenAuth() bool {
return s.authType == authTypeToken
}