git.iko.soy/typeable/servant
on master help sign in
Add basic-auth data types to servant core
commit6dc577c821b20778a74ff9d8070c86c0e4c2332a authoraaron levin <aaron.levin@soundcloud.com> dateWed 17 Feb 2016, 18:49 (11 years ago) parentc6b6639
2 files changed+33
servant/src/Servant/API.hs+4 servant/src/Servant/API/BasicAuth.hs+29
servant/src/Servant/API.hs+4
@@ -29,6 +29,9 @@ module Servant.API (
2929 -- * Actual endpoints, distinguished by HTTP method
3030 module Servant.API.Verbs,
3131
32+ -- * Authentication
33+ module Servant.API.BasicAuth,
34+
3235 -- * Content Types
3336 module Servant.API.ContentTypes,
3437 -- | Serializing and deserializing types based on @Accept@ and
@@ -51,6 +54,7 @@ module Servant.API (
5154 ) where
5255
5356import Servant.API.Alternative ((:<|>) (..))
57+import Servant.API.BasicAuth (BasicAuth,BasicAuthData(..))
5458import Servant.API.Capture (Capture)
5559import Servant.API.ContentTypes (Accept (..), FormUrlEncoded,
5660 FromFormUrlEncoded (..), JSON,
servant/src/Servant/API/BasicAuth.hsnew file+29
@@ -0,0 +1,29 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveDataTypeable #-}
3+{-# LANGUAGE KindSignatures #-}
4+{-# LANGUAGE PolyKinds #-}
5+module Servant.API.BasicAuth where
6+
7+import Data.ByteString (ByteString)
8+import Data.Typeable (Typeable)
9+import GHC.TypeLits (Symbol)
10+
11+
12+-- | Combinator for <https://tools.ietf.org/html/rfc2617#section-2 Basic Access Authentication>.
13+--
14+-- *IMPORTANT*: Only use Basic Auth over HTTPS! Credentials are not hashed or
15+-- encrypted. Note also that because the same credentials are sent on every
16+-- request, Basic Auth is not as secure as some alternatives. Further, the
17+-- implementation in servant-server does not protect against some types of
18+-- timing attacks.
19+--
20+-- In Basic Auth, username and password are base64-encoded and transmitted via
21+-- the @Authorization@ header. Handshakes are not required, making it
22+-- relatively efficient.
23+data BasicAuth (realm :: Symbol)
24+ deriving (Typeable)
25+
26+-- | A simple datatype to hold data required to decorate a request
27+data BasicAuthData = BasicAuthData { basicAuthUsername :: !ByteString
28+ , basicAuthPassword :: !ByteString
29+ }