This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
two_factor_auth.go
56 lines (46 loc) · 2.21 KB
/
two_factor_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package packngo
const twoFactorAuthAppPath = "/user/otp/app"
const twoFactorAuthSmsPath = "/user/otp/sms"
// TwoFactorAuthService interface defines available two factor authentication functions
type TwoFactorAuthService interface {
EnableApp(string) (*Response, error)
DisableApp(string) (*Response, error)
EnableSms(string) (*Response, error)
DisableSms(string) (*Response, error)
ReceiveSms() (*Response, error)
SeedApp() (string, *Response, error)
}
// TwoFactorAuthServiceOp implements TwoFactorAuthService
type TwoFactorAuthServiceOp struct {
client *Client
}
// EnableApp function enables two factor auth using authenticatior app
func (s *TwoFactorAuthServiceOp) EnableApp(token string) (resp *Response, err error) {
headers := map[string]string{"x-otp-token": token}
return s.client.DoRequestWithHeader("POST", headers, twoFactorAuthAppPath, nil, nil)
}
// EnableSms function enables two factor auth using sms
func (s *TwoFactorAuthServiceOp) EnableSms(token string) (resp *Response, err error) {
headers := map[string]string{"x-otp-token": token}
return s.client.DoRequestWithHeader("POST", headers, twoFactorAuthSmsPath, nil, nil)
}
// ReceiveSms orders the auth service to issue an SMS token
func (s *TwoFactorAuthServiceOp) ReceiveSms() (resp *Response, err error) {
return s.client.DoRequest("POST", twoFactorAuthSmsPath+"/receive", nil, nil)
}
// DisableApp function disables two factor auth using
func (s *TwoFactorAuthServiceOp) DisableApp(token string) (resp *Response, err error) {
headers := map[string]string{"x-otp-token": token}
return s.client.DoRequestWithHeader("DELETE", headers, twoFactorAuthAppPath, nil, nil)
}
// DisableSms function disables two factor auth using
func (s *TwoFactorAuthServiceOp) DisableSms(token string) (resp *Response, err error) {
headers := map[string]string{"x-otp-token": token}
return s.client.DoRequestWithHeader("DELETE", headers, twoFactorAuthSmsPath, nil, nil)
}
// SeedApp orders the auth service to issue a token via google authenticator
func (s *TwoFactorAuthServiceOp) SeedApp() (otpURI string, resp *Response, err error) {
ret := &map[string]string{}
resp, err = s.client.DoRequest("POST", twoFactorAuthAppPath+"/receive", nil, ret)
return (*ret)["otp_uri"], resp, err
}