dgrijalva / jwt-go

ARCHIVE - Golang implementation of JSON Web Tokens (JWT). This project is now maintained at:
https://github.com/golang-jwt/jwt
MIT License
10.78k stars 997 forks source link

ParseWithClaims panics with certain tokens #460

Closed benjaminmordaunt closed 3 years ago

benjaminmordaunt commented 3 years ago

ParseFromRequestWithClaims seems to panic when supplied with a token with no exp claim. I'm using a custom claims structure which includes *jwt.StandardClaims and an integer.

When a token has its ExpiresAt claim set, it is parsed fine by the restricted endpoint. But if this is not set (doesn't expire), ParseWIthClaims panics for some reason and I can't figure out why.

image

benjaminmordaunt commented 3 years ago

This is not a bug in this library. If you're having a similar problem, you need to implement your own Valid method, similar to follows:

func (c *CustomConstraints) Valid() error {
    if c.StandardClaims == nil {
        return nil
    }
    return c.StandardClaims.Valid()
}