Allow using aeson 1 (lax with min-bounds)

This commit is contained in:
akhesacaro 2021-11-18 14:10:45 +01:00
parent 62033db535
commit 05ef0dd1d3
9 changed files with 23 additions and 15 deletions

View File

@ -64,7 +64,7 @@ test-suite spec
build-depends:
hspec >= 2.5.5 && < 2.9
, QuickCheck >= 2.11.3 && < 2.15
, aeson >= 2.0.1.0 && < 3
, aeson >= 1.3.1.1 && < 3
, bytestring >= 0.10.6.0 && < 0.11
, http-client >= 0.5.13.1 && < 0.8
, http-types >= 0.12.2 && < 0.13
@ -74,7 +74,7 @@ test-suite spec
, transformers >= 0.4.2.0 && < 0.6
, wai >= 3.2.1.2 && < 3.3
, warp >= 3.2.25 && < 3.4
, jose >= 0.9 && < 0.10
, jose >= 0.7.0.0 && < 0.10
other-modules:
Servant.Auth.ClientSpec
default-language: Haskell2010

View File

@ -32,7 +32,7 @@ library
ghc-options: -Wall
build-depends:
base >= 4.10 && < 4.16
, aeson >= 2.0.1.0 && < 3
, aeson >= 1.0.0.1 && < 3
, base64-bytestring >= 1.0.0.1 && < 2
, blaze-builder >= 0.4.1.0 && < 0.5
, bytestring >= 0.10.6.0 && < 0.11
@ -41,7 +41,7 @@ library
, data-default-class >= 0.1.2.0 && < 0.2
, entropy >= 0.4.1.3 && < 0.5
, http-types >= 0.12.2 && < 0.13
, jose >= 0.9 && < 0.10
, jose >= 0.7.0.0 && < 0.10
, lens >= 4.16.1 && < 5.1
, memory >= 0.14.16 && < 0.17
, monad-time >= 0.3.1.0 && < 0.4

View File

@ -35,11 +35,12 @@ library
build-depends:
base >= 4.10 && < 4.16
, containers >= 0.6 && < 0.7
, aeson >= 2.0.1.0 && < 3
, jose >= 0.9 && < 0.10
, aeson >= 1.3.1.1 && < 3
, jose >= 0.7.0.0 && < 0.10
, lens >= 4.16.1 && < 5.1
, servant >= 0.15 && < 0.19
, text >= 1.2.3.0 && < 1.3
, unordered-containers >= 0.2.9.0 && < 0.3
exposed-modules:
Servant.Auth
Servant.Auth.JWT

View File

@ -1,10 +1,17 @@
{-# LANGUAGE CPP #-}
module Servant.Auth.JWT where
import Control.Lens ((^.))
import qualified Crypto.JWT as Jose
import Data.Aeson (FromJSON, Result (..), ToJSON, fromJSON,
toJSON)
import qualified Data.Map as Map
#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Map as KM
#else
import qualified Data.HashMap.Strict as KM
#endif
import qualified Data.Text as T
@ -17,7 +24,7 @@ import qualified Data.Text as T
class FromJWT a where
decodeJWT :: Jose.ClaimsSet -> Either T.Text a
default decodeJWT :: FromJSON a => Jose.ClaimsSet -> Either T.Text a
decodeJWT m = case Map.lookup "dat" (m ^. Jose.unregisteredClaims) of
decodeJWT m = case KM.lookup "dat" (m ^. Jose.unregisteredClaims) of
Nothing -> Left "Missing 'dat' claim"
Just v -> case fromJSON v of
Error e -> Left $ T.pack e

View File

@ -70,7 +70,7 @@ library
-- Other dependencies: Lower bound around what is in the latest Stackage LTS.
-- Here can be exceptions if we really need features from the newer versions.
build-depends:
aeson >= 2.0.1.0 && < 3
aeson >= 1.4.1.0 && < 3
, base-compat >= 0.10.5 && < 0.12
, base64-bytestring >= 1.0.0.1 && < 1.3
, exceptions >= 0.10.0 && < 0.11

View File

@ -52,7 +52,7 @@ library
-- Other dependencies: Lower bound around what is in the latest Stackage LTS.
-- Here can be exceptions if we really need features from the newer versions.
build-depends:
aeson >= 2.0.1.0 && < 3
aeson >= 1.4.1.0 && < 3
, aeson-pretty >= 0.8.5 && < 0.9
, base-compat >= 0.10.5 && < 0.12
, case-insensitive >= 1.2.0.11 && < 1.3

View File

@ -114,7 +114,7 @@ executable greet
, text
build-depends:
aeson >= 2.0.1.0 && < 3
aeson >= 1.4.1.0 && < 3
, warp >= 3.2.25 && < 3.4
test-suite spec
@ -157,7 +157,7 @@ test-suite spec
-- Additional dependencies
build-depends:
aeson >= 2.0.1.0 && < 3
aeson >= 1.4.1.0 && < 3
, directory >= 1.3.0.0 && < 1.4
, hspec >= 2.6.0 && < 2.9
, hspec-wai >= 0.10.1 && < 0.12

View File

@ -68,7 +68,7 @@ library
Servant.Swagger.Internal.TypeLevel.Every
Servant.Swagger.Internal.TypeLevel.TMap
hs-source-dirs: src
build-depends: aeson >=2.0.1.0 && <3
build-depends: aeson >=1.4.2.0 && <3
, aeson-pretty >=0.8.7 && <0.9
, base >=4.9.1.0 && <5
, base-compat >=0.10.5 && <0.12
@ -108,7 +108,7 @@ test-suite spec
build-tool-depends: hspec-discover:hspec-discover >=2.6.0 && <2.8
build-depends: base
, base-compat
, aeson >=2.0.1.0 && <3
, aeson >=1.4.2.0 && <3
, hspec >=2.6.0 && <2.8
, QuickCheck
, lens

View File

@ -98,7 +98,7 @@ library
-- Here can be exceptions if we really need features from the newer versions.
build-depends:
base-compat >= 0.10.5 && < 0.12
, aeson >= 2.0.1.0 && < 3
, aeson >= 1.4.1.0 && < 3
, attoparsec >= 0.13.2.2 && < 0.15
, bifunctors >= 5.5.3 && < 5.6
, case-insensitive >= 1.2.0.11 && < 1.3