keel/jwt/jwtclaims.go
Kevin Franklin Kim 1e7dc782c6 feat: add keeltime
2022-01-03 13:20:06 +01:00

28 lines
686 B
Go

package jwt
import (
"time"
"github.com/golang-jwt/jwt"
keeltime "github.com/foomo/keel/time"
)
// MaxTimeDifferenceBetweenNodes represents an offset that should be taken
// into account when creating e.g. jwt tokens with the `notBefore` flag.
var MaxTimeDifferenceBetweenNodes = time.Second * 30
func NewStandardClaims() jwt.StandardClaims {
now := keeltime.Now().Add(-MaxTimeDifferenceBetweenNodes)
return jwt.StandardClaims{
IssuedAt: now.Unix(),
NotBefore: now.Unix(),
}
}
func NewStandardClaimsWithLifetime(lifetime time.Duration) jwt.StandardClaims {
claims := NewStandardClaims()
claims.ExpiresAt = claims.IssuedAt + int64(lifetime.Seconds())
return claims
}