mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
28 lines
686 B
Go
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
|
|
}
|