1
0
mirror of https://github.com/Luzifer/vault-otp-ui.git synced 2024-09-19 00:53:01 +00:00

Allow overriding period

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-09-14 13:45:52 +02:00
parent 736b31d5b1
commit c4b7fb8485
Signed by: luzifer
GPG Key ID: DC2729FDD34BE99E

View File

@ -22,6 +22,7 @@ type token struct {
Name string `json:"name"`
Secret string `json:"-"`
Digits string `json:"digits"`
Period string `json:"period"`
}
func (t *token) GenerateCode(in time.Time) error {
@ -46,6 +47,14 @@ func (t *token) GenerateCode(in time.Time) error {
opts.Digits = otp.Digits(d)
}
if t.Period != "" {
p, err := strconv.Atoi(t.Period)
if err != nil {
return errors.Wrap(err, "Unable to parse period to int")
}
opts.Period = uint(p)
}
var err error
t.Code, err = totp.GenerateCodeCustom(strings.ToUpper(secret), in, opts)
return err
@ -212,6 +221,8 @@ func fetchTokenFromKey(client *api.Client, k string, respChan chan *token, wg *s
tok.Icon = v.(string)
case "digits":
tok.Digits = v.(string)
case "period":
tok.Period = v.(string)
}
}