wip
This commit is contained in:
parent
526a2e7ebc
commit
8d8b4e0453
@ -55,7 +55,7 @@ instance FromJSON JsonBook
|
|||||||
instance ToJSON PostBook
|
instance ToJSON PostBook
|
||||||
instance FromJSON PostBook
|
instance FromJSON PostBook
|
||||||
|
|
||||||
type API = Auth '[SA.BasicAuth, SA.JWT] SafeUser :> BaseAPI
|
type API = Auth '[TokenCheck, SA.BasicAuth, SA.JWT] SafeUser :> BaseAPI
|
||||||
|
|
||||||
type BaseAPI = "books" :> Get '[JSON] [JsonBook]
|
type BaseAPI = "books" :> Get '[JSON] [JsonBook]
|
||||||
:<|> "books" :> ReqBody '[JSON] PostBook :> Post '[JSON] JsonBook
|
:<|> "books" :> ReqBody '[JSON] PostBook :> Post '[JSON] JsonBook
|
||||||
|
@ -6,10 +6,12 @@
|
|||||||
{-# Language DuplicateRecordFields #-}
|
{-# Language DuplicateRecordFields #-}
|
||||||
{-# Language TypeApplications #-}
|
{-# Language TypeApplications #-}
|
||||||
{-# Language TemplateHaskell #-}
|
{-# Language TemplateHaskell #-}
|
||||||
|
{-# Language FlexibleContexts #-}
|
||||||
module Server.Auth
|
module Server.Auth
|
||||||
( SafeUser(..)
|
( SafeUser(..)
|
||||||
, authCheck
|
, authCheck
|
||||||
, AuthResult(..)
|
, AuthResult(..)
|
||||||
|
, TokenCheck
|
||||||
, requireLoggedIn)
|
, requireLoggedIn)
|
||||||
where
|
where
|
||||||
|
|
||||||
@ -56,3 +58,5 @@ authCheck app (BasicAuthData username password) = flip runReaderT app $
|
|||||||
requireLoggedIn :: (MonadLogger m, MonadThrow m, Monad m) => (SafeUser -> m a) -> AuthResult SafeUser -> m a
|
requireLoggedIn :: (MonadLogger m, MonadThrow m, Monad m) => (SafeUser -> m a) -> AuthResult SafeUser -> m a
|
||||||
requireLoggedIn f (Authenticated user) = f user
|
requireLoggedIn f (Authenticated user) = f user
|
||||||
requireLoggedIn _ u = $logError (pack (show u)) >> throwM err401
|
requireLoggedIn _ u = $logError (pack (show u)) >> throwM err401
|
||||||
|
|
||||||
|
data TokenCheck
|
||||||
|
Loading…
Reference in New Issue
Block a user