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

How do I set unregistered claims without using the deprecated unregisteredClaims or addClaim methods? #116

Open
ChrisPenner opened this issue Jul 18, 2023 · 1 comment

Comments

@ChrisPenner
Copy link

ChrisPenner commented Jul 18, 2023

The previous way to handle unregistered claims was to use these methods:

image

Which have both been deprecated, stating to "use a sub-type", which I assume means to define an instance of HasClaimsSet for some type I define;
However, there doesn't appear to be any way to actually provide unregistered claims for a custom type, since there's no lens for unregistered claims in HasClaimsSet to implement in the instance, and there's no way to create a ClaimsSet record otherwise since the _unregisteredClaims field of ClaimsSet isn't exported.

I suppose I could use the FromJSON instance of ClaimsSet to implement HasClaimsSet without using any deprecated methods, but that definitely seems like taking the long-way around and would involve introducing a possible failure point in the decoding step.

Perhaps was an claimUnregistered :: Lens' a (Map Text Value) accidentally omitted from HasClaimsSet when the other methods were deprecated?

Thanks!

@frasertweedale
Copy link
Owner

image

The design decision I took was that non-RFC7159 claims processed (or produced) by an application should be defined as first-class fields of subtypes. There is a simple example at the top of https://hackage.haskell.org/package/jose-0.10/docs/Crypto-JWT.html (data Super). You should not need to use instance FromJSON ClaimsSet to define instance HasClaimsSet for the subtype. You also need to define FromJSON (if verifying) and ToJSON (if producing) for the subtype.

How you get and set the additional fields (claims) in the subtype is up to you. Lenses, ordinary field accessors, whatever you prefer. But there will no longer be a Map of unrecognised/unregistered claims.

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