{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module DocuSign.Client.Authentication
( AuthenticationHeader (..)
, authenticationHeaderKey
) where
import Data.Aeson ( FromJSON
, ToJSON
, defaultOptions
, genericParseJSON
, genericToJSON
, parseJSON
, toJSON )
import Data.UUID ( UUID )
import Data.Text ( Text )
import DocuSign.Base.Fields ( modifyFieldLabel )
import GHC.Generics ( Generic )
import Network.HTTP.Types.Header ( HeaderName )
data AuthenticationHeader = AuthenticationHeader
{ authenticationHeaderIntegratorKey :: UUID
, authenticationHeaderUsername :: Text
, authenticationHeaderPassword :: Text
} deriving (Show, Eq, Generic)
instance FromJSON AuthenticationHeader where
parseJSON = genericParseJSON
$ modifyFieldLabel (dropLength "authenticationHeader")
$ defaultOptions
instance ToJSON AuthenticationHeader where
toJSON = genericToJSON
$ modifyFieldLabel (dropLength "authenticationHeader")
$ defaultOptions
authenticationHeaderKey :: HeaderName
authenticationHeaderKey = "X-DocuSign-Authentication"
dropLength :: String -> String -> String
dropLength = drop . length