packages feed

servant-auth-client 0.3.0.0 → 0.3.1.0

raw patch · 5 files changed

+68/−171 lines, 5 filesdep +containersdep +servant-client-coredep −Globdep −doctestdep −yamldep ~basedep ~servantdep ~servant-authPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: containers, servant-client-core

Dependencies removed: Glob, doctest, yaml

Dependency ranges changed: base, servant, servant-auth, servant-client

API changes (from Hackage documentation)

- Servant.Auth.Client.Internal: instance (Servant.Auth.Client.Internal.HasJWT auths, Servant.Client.HasClient api) => Servant.Client.HasClient (Servant.Auth.Auth auths a Servant.API.Sub.:> api)
+ Servant.Auth.Client.Internal: instance (Servant.Auth.Client.Internal.HasJWT auths, Servant.Client.Core.Internal.HasClient.HasClient m api) => Servant.Client.Core.Internal.HasClient.HasClient m (Servant.Auth.Auth auths a Servant.API.Sub.:> api)

Files

− package.yaml
@@ -1,84 +0,0 @@-name:                servant-auth-client-version:             0.3.0.0-synopsis:            servant-client/servant-auth compatibility-description:         |-    This package provides instances that allow generating clients from-    <https://hackage.haskell.org/package/servant servant>-    APIs that use-    <https://hackage.haskell.org/package/servant-auth servant-auth's> @Auth@ combinator.--    For a quick overview of the usage, see the <http://github.com/plow-technologies/servant-auth#readme README>.-homepage:            http://github.com/plow-technologies/servant-auth#readme-license:             BSD3-license-file:        LICENSE-author:              Julian K. Arni-maintainer:          jkarni@gmail.com-category:            Web, Servant, Authentication-copyright:           (c) Julian K. Arni-github:              plow-technologies/servant-auth-tested-with:         GHC == 7.10.2, GHC == 8.0.1--ghc-options: -Wall--extra-source-files:-  - package.yaml--dependencies:-  - base                >= 4.8  && < 4.10-  - text-  - bytestring-  - servant-client      >= 0.7  && < 0.12-  - servant-auth        == 0.3.*-  - servant             >= 0.7  && < 0.12--default-extensions:-  - AutoDeriveTypeable-  - ConstraintKinds-  - DataKinds-  - DefaultSignatures-  - DeriveFoldable-  - DeriveFunctor-  - DeriveGeneric-  - DeriveTraversable-  - FlexibleContexts-  - FlexibleInstances-  - FunctionalDependencies-  - GADTs-  - KindSignatures-  - MultiParamTypeClasses-  - OverloadedStrings-  - RankNTypes-  - ScopedTypeVariables-  - TypeFamilies-  - TypeOperators--library:-  source-dirs:      src-  other-modules:    []--tests:-  spec:-    main:            Spec.hs-    source-dirs:     test-    dependencies:-      - servant-auth-client-      - hspec > 2 && < 3-      - QuickCheck >= 2.8 && < 2.10-      - aeson-      - bytestring-      - http-client-      - http-types-      - servant-auth-server-      - servant-server-      - time-      - transformers-      - wai-      - warp-      - jose-  doctest:-    main:            Doctest.hs-    source-dirs:     test-    dependencies:-      - doctest >= 0.9 && < 0.12-      - Glob >= 0.7 && < 0.8-      - yaml == 0.8.*
servant-auth-client.cabal view
@@ -1,9 +1,5 @@--- This file has been generated from package.yaml by hpack version 0.17.0.------ see: https://github.com/sol/hpack- name:           servant-auth-client-version:        0.3.0.0+version:        0.3.1.0 synopsis:       servant-client/servant-auth compatibility description:    This package provides instances that allow generating clients from                 <https://hackage.haskell.org/package/servant servant>@@ -19,56 +15,44 @@ copyright:      (c) Julian K. Arni license:        BSD3 license-file:   LICENSE-tested-with:    GHC == 7.10.2, GHC == 8.0.1+tested-with:    GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.1 build-type:     Simple cabal-version:  >= 1.10 -extra-source-files:-    package.yaml- source-repository head   type: git   location: https://github.com/plow-technologies/servant-auth +flag servant-client-core+  description: Use servant-client-core+  default: True+  manual: False+ library   hs-source-dirs:       src   default-extensions: AutoDeriveTypeable ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings RankNTypes ScopedTypeVariables TypeFamilies TypeOperators   ghc-options: -Wall   build-depends:-      base                >= 4.8  && < 4.10+      base                >= 4.8  && < 4.11     , text     , bytestring-    , servant-client      >= 0.7  && < 0.12     , servant-auth        == 0.3.*-    , servant             >= 0.7  && < 0.12+    , servant             >= 0.7  && < 0.13+  if flag(servant-client-core)+    cpp-options: -DHAS_CLIENT_CORE=1+    build-depends:+      servant-client-core >= 0.12 && < 0.13,+      containers+  else+    build-depends:+      servant-client      >= 0.7  && < 0.12+   exposed-modules:       Servant.Auth.Client       Servant.Auth.Client.Internal   default-language: Haskell2010 -test-suite doctest-  type: exitcode-stdio-1.0-  main-is: Doctest.hs-  hs-source-dirs:-      test-  default-extensions: AutoDeriveTypeable ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings RankNTypes ScopedTypeVariables TypeFamilies TypeOperators-  ghc-options: -Wall-  build-depends:-      base                >= 4.8  && < 4.10-    , text-    , bytestring-    , servant-client      >= 0.7  && < 0.12-    , servant-auth        == 0.3.*-    , servant             >= 0.7  && < 0.12-    , doctest >= 0.9 && < 0.12-    , Glob >= 0.7 && < 0.8-    , yaml == 0.8.*-  other-modules:-      Servant.Auth.ClientSpec-      Spec-  default-language: Haskell2010- test-suite spec   type: exitcode-stdio-1.0   main-is: Spec.hs@@ -76,16 +60,20 @@       test   default-extensions: AutoDeriveTypeable ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings RankNTypes ScopedTypeVariables TypeFamilies TypeOperators   ghc-options: -Wall+  build-tool-depends: hspec-discover:hspec-discover++  -- dependencies with bounds inherited from the library stanza   build-depends:-      base                >= 4.8  && < 4.10-    , text-    , bytestring-    , servant-client      >= 0.7  && < 0.12-    , servant-auth        == 0.3.*-    , servant             >= 0.7  && < 0.12+      base+    , servant-client+    , servant-auth+    , servant     , servant-auth-client-    , hspec > 2 && < 3-    , QuickCheck >= 2.8 && < 2.10++  -- test dependencies+  build-depends:+      hspec > 2 && < 3+    , QuickCheck >= 2.8 && < 2.11     , aeson     , bytestring     , http-client@@ -98,6 +86,5 @@     , warp     , jose   other-modules:-      Doctest       Servant.Auth.ClientSpec   default-language: Haskell2010
src/Servant/Auth/Client/Internal.hs view
@@ -2,7 +2,7 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE UndecidableInstances       #-} {-# OPTIONS_GHC -fno-warn-orphans #-}-#if MIN_VERSION_base(4,9,0)+#if __GLASGOW_HASKELL__ == 800 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-} #endif module Servant.Auth.Client.Internal where@@ -11,36 +11,51 @@ import           Data.Monoid import           Data.Proxy         (Proxy (..)) import           Data.String        (IsString)-import qualified Data.Text.Encoding as T import           GHC.Exts           (Constraint) import           GHC.Generics       (Generic) import           Servant.API        ((:>)) import           Servant.Auth++#ifdef HAS_CLIENT_CORE+import           Servant.Client.Core+import           Data.Sequence ((<|))+#else import           Servant.Client import           Servant.Common.Req (Req (..))+import qualified Data.Text.Encoding as T+#endif  -- | A compact JWT Token. newtype Token = Token { getToken :: BS.ByteString }   deriving (Eq, Show, Read, Generic, IsString) --    -- HasJWT auths is nominally a redundant constraint, but ensures we're not-    -- trying to send a token to an API that doesn't accept them.-instance (HasJWT auths, HasClient api) => HasClient (Auth auths a :> api) where--  type Client (Auth auths a :> api) = Token -> Client api--  clientWithRoute _ req (Token token)-   = clientWithRoute (Proxy :: Proxy api)-   $ req { headers = ("Authorization", headerVal):headers req  }-     where-       -- 'servant-client' shouldn't be using a Text here; it should be using a-       -- ByteString.-       headerVal = "Bearer " <> T.decodeLatin1 token- type family HasJWT xs :: Constraint where   HasJWT (JWT ': xs) = ()   HasJWT (x ': xs)   = HasJWT xs   HasJWT '[]         = JWTAuthNotEnabled  class JWTAuthNotEnabled++-- | @'HasJWT' auths@ is nominally a redundant constraint, but ensures we're not+-- trying to send a token to an API that doesn't accept them.+#ifdef HAS_CLIENT_CORE+instance (HasJWT auths, HasClient m api) => HasClient m (Auth auths a :> api) where+  type Client m (Auth auths a :> api) = Token -> Client m api++  clientWithRoute m _ req (Token token)+    = clientWithRoute m (Proxy :: Proxy api)+    $ req { requestHeaders = ("Authorization", headerVal) <| requestHeaders req  }+      where+        headerVal = "Bearer " <> token+#else+instance (HasJWT auths, HasClient api) => HasClient (Auth auths a :> api) where+  type Client (Auth auths a :> api) = Token -> Client api++  clientWithRoute _ req (Token token)+    = clientWithRoute (Proxy :: Proxy api)+    $ req { headers = ("Authorization", headerVal):headers req  }+      where+        -- 'servant-client' shouldn't be using a Text here; it should be using a+        -- ByteString.+        headerVal = "Bearer " <> T.decodeLatin1 token+#endif
− test/Doctest.hs
@@ -1,26 +0,0 @@-module Main (main) where---- Runs doctest on all files in "src" dir. Assumes:---   (a) You are using hpack---   (b) The top-level "default-extensions" are the only extensions besides the---   ones in the files.--import System.FilePath.Glob (glob)-import Test.DocTest (doctest)-import Data.Yaml--newtype Exts = Exts { getExts :: [String] }-  deriving (Eq, Show, Read)--instance FromJSON Exts where-  parseJSON (Object v) = Exts <$> v .: "default-extensions"-  parseJSON _ = fail "expecting object"--main :: IO ()-main = do-  hpack' <- decodeFile "package.yaml"-  hpack <- case hpack' of-    Nothing -> return $ Exts []-    Just v  -> return v-  files <- glob "src/**/*.hs"-  doctest $ files ++ fmap ("-X" ++) (getExts hpack)
test/Servant/Auth/ClientSpec.hs view
@@ -17,6 +17,9 @@ import           Servant import           Servant.Client           (BaseUrl (..), Scheme (Http),                                            ServantError (FailureResponse),+#if MIN_VERSION_servant_client(0,12,0)+                                           Response(..),+#endif                                            client) import           System.IO.Unsafe         (unsafePerformIO) import           Test.Hspec@@ -60,7 +63,9 @@    it "fails when token is expired" $ \port -> property $ \user -> do     tok <- mkTok user (Just past)-#if MIN_VERSION_servant_client(0,11,0)+#if MIN_VERSION_servant_client(0,12,0)+    Left (FailureResponse (Response stat _ _ _))+#elif MIN_VERSION_servant_client(0,11,0)     Left (FailureResponse _ stat _ _) #else     Left (FailureResponse stat _ _)