mirror of https://github.com/golang-jwt/jwt.git
Merge branch 'master' of https://github.com/dakom/jwt-go into dg/pr_121
This commit is contained in:
commit
d8496232e5
34
parser.go
34
parser.go
|
@ -87,18 +87,40 @@ func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
|
||||||
// Check expiration times
|
// Check expiration times
|
||||||
vErr := &ValidationError{}
|
vErr := &ValidationError{}
|
||||||
now := TimeFunc().Unix()
|
now := TimeFunc().Unix()
|
||||||
if exp, ok := token.Claims["exp"].(float64); ok {
|
var exp, nbf int64
|
||||||
if now > int64(exp) {
|
var vexp, vnbf bool
|
||||||
|
|
||||||
|
if p.UseJSONNumber {
|
||||||
|
if num, ok := token.Claims["exp"].(json.Number); ok {
|
||||||
|
if exp, err = num.Int64(); err == nil {
|
||||||
|
vexp = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if num, ok := token.Claims["nbf"].(json.Number); ok {
|
||||||
|
if nbf, err = num.Int64(); err == nil {
|
||||||
|
vnbf = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if num, ok := token.Claims["exp"].(float64); ok {
|
||||||
|
vexp = true
|
||||||
|
exp = int64(num)
|
||||||
|
}
|
||||||
|
if num, ok := token.Claims["nbf"].(float64); ok {
|
||||||
|
vnbf = true
|
||||||
|
nbf = int64(num)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if vexp && now > exp {
|
||||||
vErr.err = "token is expired"
|
vErr.err = "token is expired"
|
||||||
vErr.Errors |= ValidationErrorExpired
|
vErr.Errors |= ValidationErrorExpired
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if nbf, ok := token.Claims["nbf"].(float64); ok {
|
if vnbf && now < nbf {
|
||||||
if now < int64(nbf) {
|
|
||||||
vErr.err = "token is not valid yet"
|
vErr.err = "token is not valid yet"
|
||||||
vErr.Errors |= ValidationErrorNotValidYet
|
vErr.Errors |= ValidationErrorNotValidYet
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Perform validation
|
// Perform validation
|
||||||
token.Signature = parts[2]
|
token.Signature = parts[2]
|
||||||
|
|
Loading…
Reference in New Issue