golang-jwt / jwt

Go implementation of JSON Web Tokens (JWT).
https://golang-jwt.github.io/jwt/
MIT License
6.98k stars 335 forks source link

Add ID to Claims interface #352

Open st3fan opened 11 months ago

st3fan commented 11 months ago

This patch adds the jti claim to the Claims interface with a GetID() method. It also implements GetID() for both MapClaims and RegisteredClaims.

This makes it easier to use the registered claims (as documented in https://datatracker.ietf.org/doc/html/rfc7519#section-4.1) when you don't know whether you have an instance of RegisteredClaims or MapClaims to work with.

(I have a a concrete use for this where it saves me a type switch to find out what type of claims I am working with)

I realize that this is a drive-by pull request - if this change is unwanted then please discard it.

oxisto commented 11 months ago

This looks like a good idea, unfortunately this is API breaking, so this is something we need to keep reserved for a future v6, so this might be "stuck" for a while.