mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-23 15:51:24 +00:00
make otp key expiry configurable
This commit is contained in:
@@ -41,7 +41,7 @@ func (e *Otp) Generate(ctx context.Context, req *pb.GenerateRequest, rsp *pb.Gen
|
|||||||
key, err := totp.Generate(totp.GenerateOpts{
|
key, err := totp.Generate(totp.GenerateOpts{
|
||||||
Issuer: "Micro",
|
Issuer: "Micro",
|
||||||
AccountName: req.Id,
|
AccountName: req.Id,
|
||||||
Period: 300,
|
Period: uint(req.Expiry),
|
||||||
Algorithm: otp.AlgorithmSHA1,
|
Algorithm: otp.AlgorithmSHA1,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -54,7 +54,7 @@ func (e *Otp) Generate(ctx context.Context, req *pb.GenerateRequest, rsp *pb.Gen
|
|||||||
Expiry: uint(req.Expiry),
|
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)
|
logger.Error("Failed to store secret: %v", err)
|
||||||
return errors.InternalServerError("otp.generate", "failed to generate code")
|
return errors.InternalServerError("otp.generate", "failed to generate code")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user