check nbf claim

This commit is contained in:
Cenk Alti 2014-02-11 22:31:34 -08:00
parent 8de1bb8a61
commit fa09d56388
1 changed files with 8 additions and 2 deletions

10
jwt.go
View File

@ -117,12 +117,18 @@ func Parse(tokenString string, keyFunc Keyfunc) (token *Token, err error) {
return return
} }
// Check expiry times // Check expiration times
now := TimeFunc().Unix()
if exp, ok := token.Claims["exp"].(float64); ok { if exp, ok := token.Claims["exp"].(float64); ok {
if TimeFunc().Unix() > int64(exp) { if now > int64(exp) {
err = errors.New("Token is expired") err = errors.New("Token is expired")
} }
} }
if nbf, ok := token.Claims["nbf"].(float64); ok {
if now < int64(nbf) {
err = errors.New("Token is not valid yet")
}
}
// Lookup key // Lookup key
var key []byte var key []byte