diff --git a/yesod-auth/ChangeLog.md b/yesod-auth/ChangeLog.md index 782e12c1..0a5c2267 100644 --- a/yesod-auth/ChangeLog.md +++ b/yesod-auth/ChangeLog.md @@ -1,5 +1,9 @@ # ChangeLog for yesod-auth +## 1.6.10.5 + +* Add support for aeson 2 + ## 1.6.10.4 * Add support for GHC 9 [#1737](https://github.com/yesodweb/yesod/pull/1737) diff --git a/yesod-auth/Yesod/Auth.hs b/yesod-auth/Yesod/Auth.hs index dd69812f..933e76f8 100644 --- a/yesod-auth/Yesod/Auth.hs +++ b/yesod-auth/Yesod/Auth.hs @@ -52,7 +52,6 @@ import Control.Monad.Trans.Maybe import UnliftIO (withRunInIO, MonadUnliftIO) import Yesod.Auth.Routes -import Data.Aeson hiding (json) import Data.Text.Encoding (decodeUtf8With) import Data.Text.Encoding.Error (lenientDecode) import Data.Text (Text) @@ -452,7 +451,7 @@ $nothing
Not logged in. |] jsonCreds creds = - Object $ Map.fromList + toJSON $ Map.fromList [ (T.pack "logged_in", Bool $ maybe False (const True) creds) ] diff --git a/yesod-auth/Yesod/Auth/GoogleEmail2.hs b/yesod-auth/Yesod/Auth/GoogleEmail2.hs index cf79a57f..fbe17d2c 100644 --- a/yesod-auth/Yesod/Auth/GoogleEmail2.hs +++ b/yesod-auth/Yesod/Auth/GoogleEmail2.hs @@ -87,7 +87,6 @@ import Data.Aeson.Types (FromJSON (parseJSON), parseEither, parseMaybe, withObject, withText) import Data.Conduit import Data.Conduit.Attoparsec (sinkParser) -import qualified Data.HashMap.Strict as M import Data.Maybe (fromMaybe) import Data.Monoid (mappend) import Data.Text (Text) @@ -103,6 +102,13 @@ import Network.HTTP.Conduit (http) import Network.HTTP.Types (renderQueryText) import System.IO.Unsafe (unsafePerformIO) +#if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.Key +import qualified Data.Aeson.KeyMap +#else +import qualified Data.HashMap.Strict as M +#endif + -- | Plugin identifier. This is used to identify the plugin used for -- authentication. The 'credsPlugin' will contain this value when this @@ -587,9 +593,19 @@ instance FromJSON EmailType where _ -> EmailType t allPersonInfo :: A.Value -> [(Text, Text)] -allPersonInfo (A.Object o) = map enc $ M.toList o - where enc (key, A.String s) = (key, s) - enc (key, v) = (key, TL.toStrict $ TL.toLazyText $ A.encodeToTextBuilder v) +allPersonInfo (A.Object o) = map enc $ mapToList o + where + enc (key, A.String s) = (keyToText key, s) + enc (key, v) = (keyToText key, TL.toStrict $ TL.toLazyText $ A.encodeToTextBuilder v) + +#if MIN_VERSION_aeson(2, 0, 0) + keyToText = Data.Aeson.Key.toText + mapToList = Data.Aeson.KeyMap.toList +#else + keyToText = id + mapToList = M.toList +#endif + allPersonInfo _ = [] diff --git a/yesod-auth/yesod-auth.cabal b/yesod-auth/yesod-auth.cabal index f5aa0bce..45a67235 100644 --- a/yesod-auth/yesod-auth.cabal +++ b/yesod-auth/yesod-auth.cabal @@ -1,6 +1,6 @@ cabal-version: >=1.10 name: yesod-auth -version: 1.6.10.4 +version: 1.6.10.5 license: MIT license-file: LICENSE author: Michael Snoyman, Patrick Brisbin