-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotp-impl.go
33 lines (26 loc) · 1.02 KB
/
otp-impl.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
package otp
import (
"github.com/xlzd/gotp"
)
// Client manage all OTP action
type Client struct{}
// GetOTP function get OTP code from OTP object
func (c *Client) GetOTP(totp *gotp.TOTP) string {
return totp.Now()
}
// Default function will generate an OTP object based on your secret
func (c *Client) Default(secret string) *gotp.TOTP {
return gotp.NewDefaultTOTP(secret)
}
// Custom function will generate an OTP object based on your secret, digits and time interval
func (c *Client) Custom(secret string, digits, interval int) *gotp.TOTP {
return gotp.NewTOTP(secret, digits, interval, nil)
}
// GoogleAuthenticator works with the Google Authenticator iPhone and Android app, as well as other OTP apps like Authy
func (c *Client) GoogleAuthenticator(secret, accountName, issuerName string) string {
return gotp.NewDefaultTOTP(secret).ProvisioningUri(accountName, issuerName)
}
// Verify your OTP with timestamp
func (c *Client) Verify(totp *gotp.TOTP, secret string, timestamp int) bool {
return totp.Verify(secret, timestamp)
}