Skip to content

Commit

Permalink
Merge pull request #165 from icey-yu/fix-token
Browse files Browse the repository at this point in the history
fix: Add a lead time for the token's issuance time.
  • Loading branch information
icey-yu authored Dec 3, 2024
2 parents f1482ba + faa5e89 commit 7c238bd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tokenverify/jwt_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

const HoursOneDay = 24
const minutesBefore = 5
const secondBefore = 5

type Claims struct {
UserID string
Expand All @@ -32,14 +32,14 @@ type Claims struct {

func BuildClaims(uid string, platformID int, ttl int64) Claims {
now := time.Now()
before := now.Add(-time.Minute * time.Duration(minutesBefore))
before := now.Add(-time.Second * time.Duration(secondBefore))
return Claims{
UserID: uid,
PlatformID: platformID,
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(now.Add(time.Duration(ttl*HoursOneDay) * time.Hour)), // Expiration time
IssuedAt: jwt.NewNumericDate(now), // Issuing time
NotBefore: jwt.NewNumericDate(before), // Begin Effective time
IssuedAt: jwt.NewNumericDate(before), // Issuing time
//NotBefore: jwt.NewNumericDate(before), // Begin Effective time
},
}
}
Expand Down

0 comments on commit 7c238bd

Please sign in to comment.