Closed fabiante closed 2 years ago
Maybe my line of thinking is too easy but why not have one claim type that works for both and just have the values empty / nil which are not relevant to the other use case? More or less a UserBotClaims
? There is not really a "dynamic" way of changing claims based on certain fields unfortunately.
You should also be able to do something like this:
type UserClaims struct {
EMail string
Name string
}
type BotClaims struct {
BotId string
}
type AllMightyClaims struct {
*BotClaims
*UserClaims
*jwt.RegisteredClaims
}
@oxisto Hm, I like the idea. I might add a TokenType string
field, which could directly contain the type, allowing an explicit switch-case for differentiation.
Hi,
I might have a a case which is kind of special but maybe there is anyone who has an idea.
I use this great package to issue two types of JWTs:
type UserClaims struct
which embeds the standard claims type. Claims are email, firstName, lastName and similar.type BotClaims struct
which also embeds the standard claims type but does not require the claims used for human users. Instead they have some special claims like botId and botType.I can't really figure out how to use
jwt.Parse
orjwt.ParseWithClaims
to allow usage of both claim types.The only idea I have is using
MapClaims
but then I'd lose the benefit of having explicit types for the two claim types.Has anyone experience with this? Sincerely.