From 8e74e33063b1a51d9861ce341497e3657e57f130 Mon Sep 17 00:00:00 2001 From: Cenk Alti Date: Wed, 5 Feb 2014 15:07:40 -0800 Subject: [PATCH] make time function overrideable --- jwt.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jwt.go b/jwt.go index 166bbbf..8c5666e 100644 --- a/jwt.go +++ b/jwt.go @@ -9,6 +9,10 @@ import ( "time" ) +// TimeFunc is used when parsing token to validate "exp" claim (expiration time). +// You can override it to use another time zone (UTC for example). +var TimeFunc = time.Now + // Parse methods use this callback function to supply // the key for verification. The function receives the parsed, // but unverified Token. This allows you to use propries in the @@ -114,7 +118,7 @@ func Parse(tokenString string, keyFunc Keyfunc) (token *Token, err error) { // Check expiry times if exp, ok := token.Claims["exp"].(float64); ok { - if time.Now().Unix() > int64(exp) { + if TimeFunc().Unix() > int64(exp) { err = errors.New("Token is expired") } }