Ability to decode non predefined fields
Closed this issue · 2 comments
yogsototh commented
I might have missed something. But I don't see how I can get claims not already predefined in JwtClaims (typically email
claim from OIDC from Google for example).
A quick fix would be to simply change the type of decodeClaims
or to add another function like this:
decodeClaims :: ByteString
-> Either JwtError (JwtHeader, JwtClaims)
decodeClaims = decodeJwt
decodeJwt :: (FromJSON a) => ByteString
-> Either JwtError (JwtHeader, a)
decodeJwt jwt = do
let components = BC.split '.' jwt
when (length components /= 3) $ Left $ BadDots 2
hdr <- B64.decode (head components) >>= parseHeader
claims <- B64.decode ((head . tail) components) >>= parseClaims
return (hdr, claims)
where
parseClaims bs = maybe (Left BadClaims) Right $ decodeStrict' bs
So I will be able to get any claim easily.
Another solution would be to change the type of JwtClaims to contains a Map for all non predefined claims.
If you believe this is reasonable I'll make a quick PR.
tekul commented
Included in version 0.8.0.
yogsototh commented
thanks!