Common OTP lib in Shell, Python and Go
build your own 2FA/MFA app with
Python
/Go
Python
import pyotp
totp = pyotp.TOTP('XXXXXXXX')
print totp.now()
Golang
package main
import (
"flag"
"fmt"
"strings"
"github.com/hgfischer/go-otp"
)
var (
length = flag.Uint("length", otp.DefaultLength, "OTP length")
period = flag.Uint("period", otp.DefaultPeriod, "Period in seconds")
)
func main() {
tokenMap := make(map[string]string)
tokenMap["sso token"] = "XXXXXXXXX"
for keyName, keyToken := range tokenMap {
totp := &otp.TOTP{
Secret: strings.ToUpper(keyToken),
Length: uint8(*length),
Period: uint8(*period),
IsBase32Secret: true,
}
fmt.Printf("%s: %s\n", keyName, totp.Get())
}
}
Shell
## Debian & Ubuntu
apt install oathtool
## Mac
brew install oathtool
oathtool -b --totp XXXXXXXXX