summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordomenkozar <>2020-10-06 08:07:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2020-10-06 08:07:00 (GMT)
commit9d9eb90355ad4e0a15ce347399a30a97b2e40fef (patch)
treea0ab2b52f7c4afd4e3a37f649f757224eba75827
parent58e94aa86849f47a67e9a99393f908bfa787c87b (diff)
version 0.4.1.0HEAD0.4.1.0master
-rwxr-xr-x[-rw-r--r--]CHANGELOG.md4
-rw-r--r--servant-auth-client.cabal20
-rw-r--r--src/Servant/Auth/Client.hs4
-rw-r--r--src/Servant/Auth/Client/Internal.hs34
4 files changed, 42 insertions, 20 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d6024c8..2ce9f58 100644..100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [PVP Versioning](https://pvp.haskell.org/).
## [Unreleased]
+## [0.4.1.0] - 2020-10-06
+
+- Support generic Bearer token auth
+
## [0.4.0.0] - 2019-03-08
## Changed
diff --git a/servant-auth-client.cabal b/servant-auth-client.cabal
index d6c1bcb..473772f 100644
--- a/servant-auth-client.cabal
+++ b/servant-auth-client.cabal
@@ -1,5 +1,5 @@
name: servant-auth-client
-version: 0.4.0.0
+version: 0.4.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>
@@ -15,7 +15,7 @@ maintainer: jkarni@gmail.com
copyright: (c) Julian K. Arni
license: BSD3
license-file: LICENSE
-tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC==8.4.4, GHC==8.6.2
+tested-with: GHC == 8.2.2, GHC==8.4.4, GHC==8.6.5, GHC==8.8.1, GHC==8.10.2
build-type: Simple
cabal-version: >= 1.10
extra-source-files:
@@ -31,12 +31,12 @@ library
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.9 && < 4.13
+ base >= 4.10 && < 4.15
, bytestring >= 0.10.6.0 && < 0.11
, containers >= 0.5.6.2 && < 0.7
, servant-auth == 0.3.*
- , servant >= 0.13 && < 0.17
- , servant-client-core >= 0.13 && < 0.17
+ , servant >= 0.13 && < 0.19
+ , servant-client-core >= 0.13 && < 0.19
exposed-modules:
Servant.Auth.Client
@@ -63,17 +63,17 @@ test-suite spec
-- test dependencies
build-depends:
hspec >= 2.5.5 && < 2.8
- , QuickCheck >= 2.11.3 && < 2.13
- , aeson >= 1.3.1.1 && < 1.5
+ , QuickCheck >= 2.11.3 && < 2.15
+ , aeson >= 1.3.1.1 && < 1.6
, bytestring >= 0.10.6.0 && < 0.11
, http-client >= 0.5.13.1 && < 0.7
, http-types >= 0.12.2 && < 0.13
, servant-auth-server >= 0.4.2.0 && < 0.5
- , servant-server >= 0.13 && < 0.17
- , time >= 1.5.0.1 && < 1.9
+ , servant-server >= 0.13 && < 0.19
+ , time >= 1.5.0.1 && < 1.10
, transformers >= 0.4.2.0 && < 0.6
, wai >= 3.2.1.2 && < 3.3
- , warp >= 3.2.25 && < 3.3
+ , warp >= 3.2.25 && < 3.4
, jose >= 0.7.0.0 && < 0.9
other-modules:
Servant.Auth.ClientSpec
diff --git a/src/Servant/Auth/Client.hs b/src/Servant/Auth/Client.hs
index 69a02fa..71e1ad8 100644
--- a/src/Servant/Auth/Client.hs
+++ b/src/Servant/Auth/Client.hs
@@ -1,3 +1,3 @@
-module Servant.Auth.Client (Token(..)) where
+module Servant.Auth.Client (Token(..), Bearer) where
-import Servant.Auth.Client.Internal (Token(..))
+import Servant.Auth.Client.Internal (Bearer, Token(..))
diff --git a/src/Servant/Auth/Client/Internal.hs b/src/Servant/Auth/Client/Internal.hs
index 866123d..4cdc9dd 100644
--- a/src/Servant/Auth/Client/Internal.hs
+++ b/src/Servant/Auth/Client/Internal.hs
@@ -19,20 +19,21 @@ import Servant.Auth
import Servant.Client.Core
import Data.Sequence ((<|))
--- | A compact JWT Token.
+-- | A simple bearer token.
newtype Token = Token { getToken :: BS.ByteString }
deriving (Eq, Show, Read, Generic, IsString)
-type family HasJWT xs :: Constraint where
- HasJWT (JWT ': xs) = ()
- HasJWT (x ': xs) = HasJWT xs
- HasJWT '[] = JWTAuthNotEnabled
+type family HasBearer xs :: Constraint where
+ HasBearer (Bearer ': xs) = ()
+ HasBearer (JWT ': xs) = ()
+ HasBearer (x ': xs) = HasBearer xs
+ HasBearer '[] = BearerAuthNotEnabled
-class JWTAuthNotEnabled
+class BearerAuthNotEnabled
--- | @'HasJWT' auths@ is nominally a redundant constraint, but ensures we're not
+-- | @'HasBearer' 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 m api) => HasClient m (Auth auths a :> api) where
+instance (HasBearer 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)
@@ -44,3 +45,20 @@ instance (HasJWT auths, HasClient m api) => HasClient m (Auth auths a :> api) wh
#if MIN_VERSION_servant_client_core(0,14,0)
hoistClientMonad pm _ nt cl = hoistClientMonad pm (Proxy :: Proxy api) nt . cl
#endif
+
+
+-- * Authentication combinators
+
+-- | A Bearer token in the Authorization header:
+--
+-- @Authorization: Bearer <token>@
+--
+-- This can be any token recognized by the server, for example,
+-- a JSON Web Token (JWT).
+--
+-- Note that, since the exact way the token is validated is not specified,
+-- this combinator can only be used in the client. The server would not know
+-- how to validate it, while the client does not care.
+-- If you want to implement Bearer authentication in your server, you have to
+-- choose a specific combinator, such as 'JWT'.
+data Bearer