make otp key expiry configurable

This commit is contained in:
Asim Aslam
2021-11-30 10:29:34 +00:00
parent 54925925af
commit 6f6686e3c1

View File

@@ -41,7 +41,7 @@ func (e *Otp) Generate(ctx context.Context, req *pb.GenerateRequest, rsp *pb.Gen
key, err := totp.Generate(totp.GenerateOpts{
Issuer: "Micro",
AccountName: req.Id,
Period: 300,
Period: uint(req.Expiry),
Algorithm: otp.AlgorithmSHA1,
})
if err != nil {
@@ -54,7 +54,7 @@ func (e *Otp) Generate(ctx context.Context, req *pb.GenerateRequest, rsp *pb.Gen
Expiry: uint(req.Expiry),
}
if err := cache.Context(ctx).Set("otp:"+req.Id, okey, time.Now().Add(time.Minute*5)); err != nil {
if err := cache.Context(ctx).Set("otp:"+req.Id, okey, time.Now().Add(time.Second*time.Duration(req.Expiry))); err != nil {
logger.Error("Failed to store secret: %v", err)
return errors.InternalServerError("otp.generate", "failed to generate code")
}