frasertweedale / hs-jose

Haskell JOSE and JWT library
http://hackage.haskell.org/package/jose
Apache License 2.0
122 stars 46 forks source link

Shall JWSHeader implement toJSON and fromJSON type class? #27

Closed haishengwu-okta closed 7 years ago

haishengwu-okta commented 7 years ago

https://hackage.haskell.org/package/jose-0.5.0.1/docs/Crypto-JOSE-JWS.html#t:JWSHeader

any particular reason it is not yet?

frasertweedale commented 7 years ago

It cannot be implemented because a JWSHeader maps to two JSON objects: the unprotected header, and the protected header (which gets base64url-encoded).

There are instances HasParams a => FromJSON (Signature a) and HasParams a => ToJSON (Signature a) for working with signatures which are "one layer out", and which perform the proper processing of unprotected and protected header parameters.

What is your use case that requires aeson instances for the JWSHeader type directly?

haishengwu-okta commented 7 years ago

I'm trying to use the JOSE.JWK.verify which needs an Alg from the JWT header.

haishengwu-okta commented 7 years ago

I guess JOSE.Compact.decodeCompact is the right one I shall use. Thanks!

frasertweedale commented 7 years ago

Yes, JWT is a whole other issue... JWT is defined to use only the compact serialisation, so there's no aeson instances for JWT.