mirror of
https://github.com/Luzifer/vault-otp-ui.git
synced 2024-11-08 08:10:11 +00:00
Allow overriding period
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
736b31d5b1
commit
c4b7fb8485
1 changed files with 11 additions and 0 deletions
11
token.go
11
token.go
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue