module Network.Hawk.Server.Types
( AuthResult
, AuthResult'(..)
, AuthFail(..)
, AuthSuccess(..)
, Credentials(..)
, HeaderArtifacts(..)
, CredentialsFunc
, HawkReq(..)
, module Network.Hawk.Types
) where
import Data.ByteString (ByteString)
import Data.Text (Text)
import Data.Time.Clock.POSIX (POSIXTime)
import Network.HTTP.Types.Method (Method)
import GHC.Generics
import Data.Default
import Network.Hawk.Types
type AuthResult t = AuthResult' (AuthSuccess t)
type AuthResult' r = Either AuthFail r
data AuthFail = AuthFailBadRequest String (Maybe HeaderArtifacts)
| AuthFailUnauthorized String (Maybe Credentials) (Maybe HeaderArtifacts)
| AuthFailStaleTimeStamp String Credentials HeaderArtifacts
deriving Show
data AuthSuccess t = AuthSuccess Credentials HeaderArtifacts t
instance Show t => Show (AuthSuccess t)
data HawkReq = HawkReq
{ hrqMethod :: Method
, hrqUrl :: ByteString
, hrqHost :: ByteString
, hrqPort :: Maybe Int
, hrqAuthorization :: ByteString
, hrqPayload :: Maybe PayloadInfo
, hrqBewit :: Maybe ByteString
, hrqBewitlessUrl :: ByteString
} deriving Show
instance Default HawkReq where
def = HawkReq "GET" "/" "localhost" Nothing "" Nothing Nothing ""
data Credentials = Credentials
{ scKey :: Key
, scAlgorithm :: HawkAlgo
} deriving (Show, Generic)
data HeaderArtifacts = HeaderArtifacts
{ shaMethod :: Method
, shaHost :: ByteString
, shaPort :: Maybe Int
, shaResource :: ByteString
, shaId :: ClientId
, shaTimestamp :: POSIXTime
, shaNonce :: ByteString
, shaMac :: ByteString
, shaHash :: Maybe ByteString
, shaExt :: Maybe ByteString
, shaApp :: Maybe Text
, shaDlg :: Maybe ByteString
} deriving Show
type CredentialsFunc m t = ClientId -> m (Either String (Credentials, t))