mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-27 20:36:29 -04:00
Handle Steam TOTP directly in GenTOTP
This commit is contained in:
+6
-11
@@ -11,13 +11,14 @@ import (
|
|||||||
"github.com/pquerna/otp/totp"
|
"github.com/pquerna/otp/totp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenTOTP generates a TOTP token from a secret (supports standard and Steam TOTP).
|
// GenTOTP generates a TOTP token from a secret.
|
||||||
func GenTOTP(secret string, time time.Time, forSteam bool) (string, error) {
|
// Prefix `secret` with "steam@" for Steam TOTP format.
|
||||||
|
func GenTOTP(secret string, time time.Time) (string, error) {
|
||||||
var totpToken string
|
var totpToken string
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if forSteam {
|
if strings.HasPrefix(secret, "steam@") {
|
||||||
totpToken, err = totp.GenerateCodeCustom(secret, time, totp.ValidateOpts{Period: 30, Digits: 5, Encoder: otp.EncoderSteam})
|
totpToken, err = totp.GenerateCodeCustom(secret[6:], time, totp.ValidateOpts{Period: 30, Digits: 5, Encoder: otp.EncoderSteam})
|
||||||
} else {
|
} else {
|
||||||
totpToken, err = totp.GenerateCode(secret, time)
|
totpToken, err = totp.GenerateCode(secret, time)
|
||||||
}
|
}
|
||||||
@@ -32,15 +33,9 @@ func GenTOTP(secret string, time time.Time, forSteam bool) (string, error) {
|
|||||||
// TOTPCopier is meant to be run as a goroutine to keep
|
// TOTPCopier is meant to be run as a goroutine to keep
|
||||||
// the clipboard up-to-date with the latest TOTP token.
|
// the clipboard up-to-date with the latest TOTP token.
|
||||||
func TOTPCopier(secret string, errorChan chan<- error, done <-chan bool) {
|
func TOTPCopier(secret string, errorChan chan<- error, done <-chan bool) {
|
||||||
var forSteam bool
|
|
||||||
if strings.HasPrefix(secret, "steam@") {
|
|
||||||
secret = secret[6:]
|
|
||||||
forSteam = true
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
token, err := GenTOTP(secret, currentTime, forSteam)
|
token, err := GenTOTP(secret, currentTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorChan <- err
|
errorChan <- err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user