From cedd7c3e60e079e8e07e9b5ba2121ce98a11decb Mon Sep 17 00:00:00 2001 From: Jeremy Shaw Date: Tue, 26 Apr 2022 12:30:15 -0500 Subject: [PATCH 1/2] 2.6.1 - updates for JWT, aeson, etc --- .github/workflows/haskell-ci.yml | 16 ++++++++-------- Happstack/Authenticate/Core.hs | 5 ++++- Happstack/Authenticate/OpenId/Core.hs | 6 ++++-- Happstack/Authenticate/Password/Core.hs | 11 ++++++++++- README.md | 2 +- happstack-authenticate.cabal | 14 +++++++------- 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index fce1cb2..94a7e9d 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -28,9 +28,9 @@ jobs: strategy: matrix: include: - - compiler: ghc-9.2.1 + - compiler: ghc-9.2.2 compilerKind: ghc - compilerVersion: 9.2.1 + compilerVersion: 9.2.2 setup-method: ghcup allow-failure: false - compiler: ghc-9.0.2 @@ -43,9 +43,9 @@ jobs: compilerVersion: 8.10.7 setup-method: ghcup allow-failure: false - - compiler: ghc-8.8.3 + - compiler: ghc-8.8.4 compilerKind: ghc - compilerVersion: 8.8.3 + compilerVersion: 8.8.4 setup-method: hvr-ppa allow-failure: false - compiler: ghc-8.6.5 @@ -53,9 +53,9 @@ jobs: compilerVersion: 8.6.5 setup-method: hvr-ppa allow-failure: false - - compiler: ghc-8.4.1 + - compiler: ghc-8.4.4 compilerKind: ghc - compilerVersion: 8.4.1 + compilerVersion: 8.4.4 setup-method: hvr-ppa allow-failure: false - compiler: ghc-8.2.2 @@ -63,9 +63,9 @@ jobs: compilerVersion: 8.2.2 setup-method: hvr-ppa allow-failure: false - - compiler: ghc-8.0.1 + - compiler: ghc-8.0.2 compilerKind: ghc - compilerVersion: 8.0.1 + compilerVersion: 8.0.2 setup-method: hvr-ppa allow-failure: false fail-fast: false diff --git a/Happstack/Authenticate/Core.hs b/Happstack/Authenticate/Core.hs index d1491c9..9a3f60a 100644 --- a/Happstack/Authenticate/Core.hs +++ b/Happstack/Authenticate/Core.hs @@ -168,6 +168,7 @@ import System.Random (randomRIO) import Text.Boomerang.TH (makeBoomerangs) import Text.Shakespeare.I18N (RenderMessage(renderMessage), mkMessageFor) import Web.JWT (Algorithm(HS256), JWT, VerifiedJWT, JWTClaimsSet(..), encodeSigned, claims, decode, decodeAndVerifySignature, secondsSinceEpoch, intDate, verify) +import qualified Web.JWT as JWT #if MIN_VERSION_jwt(0,8,0) import Web.JWT (ClaimsMap(..), hmacSecret) #else @@ -734,7 +735,9 @@ decodeAndVerifyToken authenticateState now token = Nothing -> return Nothing (Just ssecret) -> -- finally we can verify all the claims -#if MIN_VERSION_jwt(0,8,0) +#if MIN_VERSION_jwt(0,11,0) + case verify (JWT.toVerify $ hmacSecret (_unSharedSecret ssecret)) unverified of +#elif MIN_VERSION_jwt(0,8,0) case verify (hmacSecret (_unSharedSecret ssecret)) unverified of #else case verify (secret (_unSharedSecret ssecret)) unverified of diff --git a/Happstack/Authenticate/OpenId/Core.hs b/Happstack/Authenticate/OpenId/Core.hs index 80b267a..13c4b6f 100644 --- a/Happstack/Authenticate/OpenId/Core.hs +++ b/Happstack/Authenticate/OpenId/Core.hs @@ -82,13 +82,15 @@ data OpenIdState = OpenIdState , _openIdRealm :: Maybe Text } deriving (Eq, Ord, Read, Show, Data, Typeable, Generic) -deriveSafeCopy 2 'extension ''OpenIdState -makeLenses ''OpenIdState instance Migrate OpenIdState where type MigrateFrom OpenIdState = OpenIdState_1 migrate (OpenIdState_1 ids) = OpenIdState ids Nothing +deriveSafeCopy 2 'extension ''OpenIdState +makeLenses ''OpenIdState + + initialOpenIdState :: OpenIdState initialOpenIdState = OpenIdState { _identifiers = Map.fromList [] diff --git a/Happstack/Authenticate/Password/Core.hs b/Happstack/Authenticate/Password/Core.hs index 16e2ac5..dee43b0 100644 --- a/Happstack/Authenticate/Password/Core.hs +++ b/Happstack/Authenticate/Password/Core.hs @@ -13,6 +13,9 @@ import Data.Acid.Local (createCheckpointAndClose, openLocalStateFrom) import qualified Data.Aeson as Aeson import Data.Aeson (Value(..), Object(..), Result(..), decode, encode, fromJSON) import Data.Aeson.Types (ToJSON(..), FromJSON(..), Options(fieldLabelModifier), defaultOptions, genericToJSON, genericParseJSON) +#if MIN_VERSION_aeson(2,0,0) +import qualified Data.Aeson.KeyMap as KM +#endif import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as B import Data.Data (Data, Typeable) @@ -220,7 +223,11 @@ token authenticateState authenticateConfig passwordState = if not valid then unauthorized $ toJSONError InvalidUsernamePassword else do token <- addTokenCookie authenticateState authenticateConfig u +#if MIN_VERSION_aeson(2,0,0) + resp 201 $ toJSONSuccess (Object $ KM.fromList [("token", toJSON token)]) -- toResponseBS "application/json" $ encode $ Object $ HashMap.fromList [("token", toJSON token)] +#else resp 201 $ toJSONSuccess (Object $ HashMap.fromList [("token", toJSON token)]) -- toResponseBS "application/json" $ encode $ Object $ HashMap.fromList [("token", toJSON token)] +#endif ------------------------------------------------------------------------------ -- account @@ -510,7 +517,9 @@ decodeAndVerifyResetToken authenticateState token = case mssecret of Nothing -> return Nothing (Just ssecret) -> -#if MIN_VERSION_jwt(0,8,0) +#if MIN_VERSION_jwt(0,11,0) + case verify (JWT.toVerify $ hmacSecret (_unSharedSecret ssecret)) unverified of +#elif MIN_VERSION_jwt(0,8,0) case verify (hmacSecret (_unSharedSecret ssecret)) unverified of #else case verify (secret (_unSharedSecret ssecret)) unverified of diff --git a/README.md b/README.md index e85ba32..79cf35a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -happstack-authenticate [![Hackage](https://img.shields.io/hackage/v/happstack-authenticate.svg)](https://hackage.haskell.org/package/happstack-authenticate) [![Build Status](https://api.travis-ci.com/Happstack/happstack-authenticate.svg?branch=master)](https://travis-ci.com/Happstack/happstack-authenticate) +happstack-authenticate [![Hackage](https://img.shields.io/hackage/v/happstack-authenticate.svg)](https://hackage.haskell.org/package/happstack-authenticate) ========= This is a rewrite of the happstack-authenticate library. The original version was too clever in all the wrong areas making things like resetting your lost password impossible. diff --git a/happstack-authenticate.cabal b/happstack-authenticate.cabal index deed3dd..82da8b0 100644 --- a/happstack-authenticate.cabal +++ b/happstack-authenticate.cabal @@ -1,5 +1,5 @@ Name: happstack-authenticate -Version: 2.6.0 +Version: 2.6.1 Synopsis: Happstack Authentication Library Description: A themeable authentication library with support for username+password and OpenId. Homepage: http://www.happstack.com/ @@ -11,7 +11,7 @@ Copyright: 2011-2015 SeeReason Partners, LLC Category: Web Build-type: Simple Cabal-version: >=1.10 -tested-with: GHC==8.0.1, GHC==8.2.2, GHC==8.4.1, GHC==8.6.5, GHC==8.8.3, GHC==8.10.7 +tested-with: GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.5, GHC==8.8.4, GHC==8.10.7, GHC==9.0.2, GHC==9.2.2 data-files: messages/core/en.msg messages/openid/error/en.msg @@ -44,7 +44,7 @@ Library Build-depends: base > 4 && < 5, acid-state >= 0.6 && < 0.17, - aeson (>= 0.4 && < 0.10) || (>= 0.11 && < 1.6), + aeson (>= 0.4 && < 0.10) || (>= 0.11 && < 1.6) || (>= 2.0 && < 2.1), authenticate == 1.3.*, base64-bytestring >= 1.0 && < 1.3, boomerang >= 1.4 && < 1.5, @@ -55,7 +55,7 @@ Library filepath >= 1.3 && < 1.5, hsx2hs >= 0.13 && < 0.15, jmacro >= 0.6.11 && < 0.7, - jwt >= 0.3 && < 0.11, + jwt >= 0.3 && < 0.12, ixset-typed >= 0.3 && < 0.6, happstack-jmacro >= 7.0 && < 7.1, happstack-server >= 6.0 && < 7.8, @@ -67,11 +67,11 @@ Library safecopy >= 0.8 && < 0.11, mime-mail >= 0.4 && < 0.6, mtl >= 2.0 && < 2.3, - lens >= 4.2 && < 4.20, + lens >= 4.2 && < 5.2, pwstore-purehaskell == 2.1.*, stm >= 2.5 && < 2.6, - text >= 0.11 && < 1.3, - time >= 1.2 && < 1.12, + text >= 0.11 && < 2.1, + time >= 1.2 && < 1.14, userid >= 0.1 && < 0.2, random >= 1.0 && < 1.3, shakespeare >= 2.0 && < 2.1, From 60be003414c8a2277fd0a6bfde1e6fa699032b80 Mon Sep 17 00:00:00 2001 From: Jeremy Shaw Date: Tue, 26 Apr 2022 14:14:07 -0500 Subject: [PATCH 2/2] allow older stm 2.4 --- happstack-authenticate.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/happstack-authenticate.cabal b/happstack-authenticate.cabal index 82da8b0..f4dae97 100644 --- a/happstack-authenticate.cabal +++ b/happstack-authenticate.cabal @@ -69,7 +69,7 @@ Library mtl >= 2.0 && < 2.3, lens >= 4.2 && < 5.2, pwstore-purehaskell == 2.1.*, - stm >= 2.5 && < 2.6, + stm >= 2.4 && < 2.6, text >= 0.11 && < 2.1, time >= 1.2 && < 1.14, userid >= 0.1 && < 0.2,