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

jwt: support custom header types #124

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

frasertweedale
Copy link
Owner

Generalise the types of signJWT, verifyJWT, and related functions to accept custom JWS header types. Add new type synonym SignedJWTWithHeader h (keeping SignedJWT as is). This change could break some applications by introducing type ambiguity. The solution is to add a type annotation or apply a function like:

fixType = id :: SignedJWT -> SignedJWT

I applied this technique in the test suite to address such ambiguity.

Fixes: #122

@frasertweedale
Copy link
Owner Author

ping @ericpashman - could you please review this PR and advise if it meets your needs per #122?

@frasertweedale frasertweedale force-pushed the fix/122-jwt-generalised-header branch 2 times, most recently from 48ed92d to 1534de5 Compare February 15, 2024 07:58
Generalise the types of `signJWT`, `verifyJWT`, and related
functions to accept custom JWS header types.  Add new type synonym
`SignedJWTWithHeader h` (keeping `SignedJWT` *as is*).  This change
could break some applications by introducing type ambiguity.
Possible solutions include…

Type application:

```haskell
{-# LANGUAGE TypeApplications #-}
decodeCompact @SignedJWT s >>= verifyClaims settings k
```

Type annotation:

```haskell
do
  jwt <- decodeCompact s
  verifyClaims settings k (jwt :: SignedJWT)
```

Explicitly typed coercion function:

```haskell
let
  fixType = id :: SignedJWT -> SignedJWT
in
  verifyClaims settings k . fixType =<< decodeCompact s
```

I used type applications in the test suite to address the ambiguity.

Fixes: #122
@frasertweedale frasertweedale merged commit b7c0a38 into master Feb 15, 2024
14 checks passed
@frasertweedale frasertweedale deleted the fix/122-jwt-generalised-header branch February 15, 2024 09:00
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

Successfully merging this pull request may close these issues.

Better support JWT with custom headers (doc, mostly)
1 participant