2017-09-12 18:38:52 +02:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
2016-02-17 21:45:08 +01:00
|
|
|
{-# LANGUAGE TypeSynonymInstances #-}
|
|
|
|
|
|
|
|
-- | Authentication for clients
|
|
|
|
|
2017-09-07 19:05:12 +02:00
|
|
|
module Servant.Client.Core.Internal.Auth where
|
2016-02-17 21:45:08 +01:00
|
|
|
|
2018-06-30 21:17:08 +02:00
|
|
|
import Servant.Client.Core.Internal.Request
|
|
|
|
(Request)
|
2016-02-17 21:45:08 +01:00
|
|
|
|
|
|
|
-- | 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
|
2017-09-13 18:36:20 +02:00
|
|
|
newtype AuthenticatedRequest a =
|
|
|
|
AuthenticatedRequest { unAuthReq :: (AuthClientData a, AuthClientData a -> Request -> Request) }
|
2016-02-17 21:45:08 +01:00
|
|
|
|
|
|
|
-- | 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
|
2017-09-13 18:36:20 +02:00
|
|
|
mkAuthenticatedRequest :: AuthClientData a
|
2017-09-06 23:13:05 +02:00
|
|
|
-> (AuthClientData a -> Request -> Request)
|
2017-09-13 18:36:20 +02:00
|
|
|
-> AuthenticatedRequest a
|
|
|
|
mkAuthenticatedRequest val func = AuthenticatedRequest (val, func)
|