Two- / Multi- Factor Authenication (2FA / MFA) for Golang
To get the package, execute:
go get github.com/dev-templates/googleauthenticator
package main
import (
"fmt"
"github.com/dev-templates/googleauthenticator"
)
func main {
// generate key
formattedKey := googleauthenticator.GenerateKey()
authenticator := googleauthenticator.NewAuthenticator("issuer", "xxx@gmail.com", formattedKey)
// generate uri for show
uri := authenticator.GenerateTotpUri()
fmt.Println(uri)
// verify token
passcode := "<from input>"
if authenticator.VerifyToken(passcode) {
// ok
}
}