2016-02-17 21:45:08 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE TypeSynonymInstances #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
|
|
|
|
|
|
-- | Authentication for clients
|
|
|
|
|
|
|
|
module Servant.Common.Auth (
|
|
|
|
AuthenticateReq(AuthenticateReq, unAuthReq)
|
|
|
|
, AuthClientData
|
|
|
|
, mkAuthenticateReq
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Servant.Common.Req (Req)
|
|
|
|
|
|
|
|
-- | For a resource protected by authentication (e.g. AuthProtect), we need
|
|
|
|
-- to provide the client with some data used to add authentication data
|
|
|
|
-- to a request
|
2016-02-17 22:01:54 +01:00
|
|
|
--
|
|
|
|
-- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE
|
2016-02-17 21:45:08 +01:00
|
|
|
type family AuthClientData a :: *
|
|
|
|
|
|
|
|
-- | For better type inference and to avoid usage of a data family, we newtype
|
|
|
|
-- wrap the combination of some 'AuthClientData' and a function to add authentication
|
|
|
|
-- data to a request
|
2016-02-17 22:01:54 +01:00
|
|
|
--
|
|
|
|
-- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE
|
2016-02-17 21:45:08 +01:00
|
|
|
newtype AuthenticateReq a =
|
|
|
|
AuthenticateReq { unAuthReq :: (AuthClientData a, AuthClientData a -> Req -> Req) }
|
|
|
|
|
|
|
|
-- | Handy helper to avoid wrapping datatypes in tuples everywhere.
|
2016-02-17 22:01:54 +01:00
|
|
|
--
|
|
|
|
-- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE
|
2016-02-17 21:45:08 +01:00
|
|
|
mkAuthenticateReq :: AuthClientData a
|
|
|
|
-> (AuthClientData a -> Req -> Req)
|
|
|
|
-> AuthenticateReq a
|
|
|
|
mkAuthenticateReq val func = AuthenticateReq (val, func)
|