Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to decode non predefined fields #21

Closed
yogsototh opened this issue Jul 7, 2018 · 2 comments
Closed

Ability to decode non predefined fields #21

yogsototh opened this issue Jul 7, 2018 · 2 comments

Comments

@yogsototh
Copy link
Contributor

yogsototh commented Jul 7, 2018

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 pushed a commit that referenced this issue Jul 26, 2018
This allows other custom JSON types to be used in addition to the
hard-coded JwtClaims type.

See #21, 22.
@tekul
Copy link
Owner

tekul commented Aug 2, 2018

Included in version 0.8.0.

@tekul tekul closed this as completed Aug 2, 2018
@yogsototh
Copy link
Contributor Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants