-
Hi all, I am migrating my project from github.com/dgrijalva/jwt-go. I found that now the My project uses a custom struct for claims, like this:
When migrating to v5 jwt-go, compiler complains that the
I am confused since those new added getters are just return corresponding fields introduced by Also, since those getters just return the corresponding fields, I cannot imagine when those getters could throw error, when could those getters return error? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Ok a couple of points
Yes, it is primarily to follow the RFC standard. All fields which are optional in the RFC are optional though and can either be set to The only function you might want to implement is Lines 127 to 134 in 1691aa9 Note: that this is performed in addition to regular validation, so you don't need to check the
There are specific corner-cases and those are the
You are welcome :) PS: It might be worth to have another look in the JWT RFCs and possible the ouath ones, there are a couple of "standard" fields that you could re-use, for example |
Beta Was this translation helpful? Give feedback.
-
Thanks @oxisto for your quick response! |
Beta Was this translation helpful? Give feedback.
Ok a couple of points
Yes, it is primarily to follow the RFC standard. All fields which are optional in the RFC are optional though and can either be set to
nil
, e.g, for date-fields or an empty string or an empty array. Since you already embeddingjwt.RegisteredClaims
in your new example, you don't need to implement the interface. Go will check embedded structs, whether they implement the necessary function…