Replies: 1 comment 2 replies
-
There are basically two options:
type MyClaims struct {
jwt.RegisteredClaims
This *string
That *string
TheOther *int
} and then check for the existence in
type MyClaims jwt.MapClaims
func (m MyClaims) Validate error() {
// Just use the map here
value, ok := m["my claim"]
} You might need to explicitly cast Update: no cast needed, you can just directly access the map values this way. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The
ClaimsValidator
interface provides a way to have a claims implementation that has its own (additional) claims validation. The examples I see in code are all using thejwt.RegisteredClaims
as a base, extending by a specific claim.What about the case where you have arbitrary additional claims, the expected values of which (to be validated against) you only know at run time because they are e.g. read from a configuration?
Currently I use
jwt.MapClaims
as input toParseWithClaims()
and then validate the claims after parsing. How could I do it during parsing with theClaimsValidator
interface?Beta Was this translation helpful? Give feedback.
All reactions