module Yu.Auth
(
checkAuth
,
Auth(..)
,
module Yu.Auth.Core
) where
import Control.Monad.IO.Class
import Yesod.Core
import Yu.Auth.Core
import Yu.Import.ByteString (ByteString)
import qualified Yu.Import.ByteString as B
class HashAlgorithm a => Auth site a | site -> a where
tokenHash :: MonadIO m => site -> m a
tokenItem :: MonadIO m => site -> m ByteString
checkAuth :: Auth site hash
=> HandlerT site IO AuthResult
checkAuth = do
site <- getYesod
item <- tokenItem site
hash <- tokenHash site
token <- lookupHeader "token"
liftIO $ print $ generateHash hash item
liftIO $ print token
case verifyHash hash item <$> token of
Just True -> return Authorized
_ -> return $ Unauthorized "Who are you! The thing did not answer."