Skip to content

Commit 119e54a

Browse files
committed
repatriation of servant-auth in the main servant repo
1 parent 26b01f0 commit 119e54a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3334
-0
lines changed

cabal.project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
packages:
22
servant/
3+
servant-auth/servant-auth
4+
servant-auth/servant-auth-client
5+
servant-auth/servant-auth-docs
6+
servant-auth/servant-auth-server
7+
servant-auth/servant-auth-swagger
8+
39
servant-client/
410
servant-client-core/
511
servant-http-streams/

servant-auth/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
servant-auth-server/README.lhs

servant-auth/RELEASE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- update changelog
2+
- bump version in cabal file
3+
- stack sdist servant-auth-server
4+
- git commit -m "v0.4.0.0"
5+
- git tag -s servant-auth-server-0.4.0.0
6+
- git push --tags
7+
- stack upload servant-auth-server
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:set -isrc -itest -idoctest/ghci-wrapper/src
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6+
and this project adheres to [PVP Versioning](https://pvp.haskell.org/).
7+
8+
## [Unreleased]
9+
10+
## [0.4.1.0] - 2020-10-06
11+
12+
- Support generic Bearer token auth
13+
14+
## [0.4.0.0] - 2019-03-08
15+
16+
## Changed
17+
18+
- #145 Support servant-0.16 in tests @domenkozar
19+
- #145 Drop GHC 7.10 support @domenkozar
20+
21+
## [0.3.3.0] - 2018-06-18
22+
23+
### Added
24+
- Support for GHC 8.4 by @phadej
25+
- Support for servant-0.14 by @phadej
26+
- Changelog by @domenkozar
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Copyright Julian K. Arni (c) 2015
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Julian K. Arni nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: servant-auth-client
2+
version: 0.4.1.0
3+
synopsis: servant-client/servant-auth compatibility
4+
description: This package provides instances that allow generating clients from
5+
<https://hackage.haskell.org/package/servant servant>
6+
APIs that use
7+
<https://hackage.haskell.org/package/servant-auth servant-auth's> @Auth@ combinator.
8+
.
9+
For a quick overview of the usage, see the <http://github.com/haskell-servant/servant-auth#readme README>.
10+
category: Web, Servant, Authentication
11+
homepage: http://github.com/haskell-servant/servant-auth#readme
12+
bug-reports: https://github.com/haskell-servant/servant-auth/issues
13+
author: Julian K. Arni
14+
maintainer: [email protected]
15+
copyright: (c) Julian K. Arni
16+
license: BSD3
17+
license-file: LICENSE
18+
tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.4 || ==9.0.1
19+
build-type: Simple
20+
cabal-version: >= 1.10
21+
extra-source-files:
22+
CHANGELOG.md
23+
24+
source-repository head
25+
type: git
26+
location: https://github.com/haskell-servant/servant-auth
27+
28+
library
29+
hs-source-dirs:
30+
src
31+
default-extensions: ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings RankNTypes ScopedTypeVariables TypeFamilies TypeOperators
32+
ghc-options: -Wall
33+
build-depends:
34+
base >= 4.10 && < 4.16
35+
, bytestring >= 0.10.6.0 && < 0.11
36+
, containers >= 0.5.6.2 && < 0.7
37+
, servant-auth == 0.4.*
38+
, servant >= 0.13 && < 0.19
39+
, servant-client-core >= 0.13 && < 0.19
40+
41+
exposed-modules:
42+
Servant.Auth.Client
43+
Servant.Auth.Client.Internal
44+
default-language: Haskell2010
45+
46+
test-suite spec
47+
type: exitcode-stdio-1.0
48+
main-is: Spec.hs
49+
hs-source-dirs:
50+
test
51+
default-extensions: ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings RankNTypes ScopedTypeVariables TypeFamilies TypeOperators
52+
ghc-options: -Wall
53+
build-tool-depends: hspec-discover:hspec-discover >=2.5.5 && <2.9
54+
55+
-- dependencies with bounds inherited from the library stanza
56+
build-depends:
57+
base
58+
, servant-client
59+
, servant-auth
60+
, servant
61+
, servant-auth-client
62+
63+
-- test dependencies
64+
build-depends:
65+
hspec >= 2.5.5 && < 2.9
66+
, QuickCheck >= 2.11.3 && < 2.15
67+
, aeson >= 1.3.1.1 && < 1.6
68+
, bytestring >= 0.10.6.0 && < 0.11
69+
, http-client >= 0.5.13.1 && < 0.8
70+
, http-types >= 0.12.2 && < 0.13
71+
, servant-auth-server >= 0.4.2.0 && < 0.5
72+
, servant-server >= 0.13 && < 0.19
73+
, time >= 1.5.0.1 && < 1.13
74+
, transformers >= 0.4.2.0 && < 0.6
75+
, wai >= 3.2.1.2 && < 3.3
76+
, warp >= 3.2.25 && < 3.4
77+
, jose >= 0.7.0.0 && < 0.9
78+
other-modules:
79+
Servant.Auth.ClientSpec
80+
default-language: Haskell2010
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Servant.Auth.Client (Token(..), Bearer) where
2+
3+
import Servant.Auth.Client.Internal (Bearer, Token(..))
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3+
{-# LANGUAGE UndecidableInstances #-}
4+
{-# OPTIONS_GHC -fno-warn-orphans #-}
5+
#if __GLASGOW_HASKELL__ == 800
6+
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
7+
#endif
8+
module Servant.Auth.Client.Internal where
9+
10+
import qualified Data.ByteString as BS
11+
import Data.Monoid
12+
import Data.Proxy (Proxy (..))
13+
import Data.String (IsString)
14+
import GHC.Exts (Constraint)
15+
import GHC.Generics (Generic)
16+
import Servant.API ((:>))
17+
import Servant.Auth
18+
19+
import Servant.Client.Core
20+
import Data.Sequence ((<|))
21+
22+
-- | A simple bearer token.
23+
newtype Token = Token { getToken :: BS.ByteString }
24+
deriving (Eq, Show, Read, Generic, IsString)
25+
26+
type family HasBearer xs :: Constraint where
27+
HasBearer (Bearer ': xs) = ()
28+
HasBearer (JWT ': xs) = ()
29+
HasBearer (x ': xs) = HasBearer xs
30+
HasBearer '[] = BearerAuthNotEnabled
31+
32+
class BearerAuthNotEnabled
33+
34+
-- | @'HasBearer' auths@ is nominally a redundant constraint, but ensures we're not
35+
-- trying to send a token to an API that doesn't accept them.
36+
instance (HasBearer auths, HasClient m api) => HasClient m (Auth auths a :> api) where
37+
type Client m (Auth auths a :> api) = Token -> Client m api
38+
39+
clientWithRoute m _ req (Token token)
40+
= clientWithRoute m (Proxy :: Proxy api)
41+
$ req { requestHeaders = ("Authorization", headerVal) <| requestHeaders req }
42+
where
43+
headerVal = "Bearer " <> token
44+
45+
#if MIN_VERSION_servant_client_core(0,14,0)
46+
hoistClientMonad pm _ nt cl = hoistClientMonad pm (Proxy :: Proxy api) nt . cl
47+
#endif
48+
49+
50+
-- * Authentication combinators
51+
52+
-- | A Bearer token in the Authorization header:
53+
--
54+
-- @Authorization: Bearer <token>@
55+
--
56+
-- This can be any token recognized by the server, for example,
57+
-- a JSON Web Token (JWT).
58+
--
59+
-- Note that, since the exact way the token is validated is not specified,
60+
-- this combinator can only be used in the client. The server would not know
61+
-- how to validate it, while the client does not care.
62+
-- If you want to implement Bearer authentication in your server, you have to
63+
-- choose a specific combinator, such as 'JWT'.
64+
data Bearer

0 commit comments

Comments
 (0)