Authentication

This commit is contained in:
2018-08-04 23:43:26 +03:00
parent 964972858b
commit 4a3e598f8a
6 changed files with 53 additions and 12 deletions

View File

@ -9,21 +9,30 @@
{-# Language RecordWildCards #-}
{-# Language DeriveGeneric #-}
{-# Language FlexibleInstances #-}
{-# Language TypeApplications #-}
module Server where
import qualified API as API
import qualified API.Users as Users
import Servant
import Types
import ClassyPrelude hiding (Handler)
import Control.Monad.Logger
import Control.Monad.Except
import Servant.Auth.Server
import Control.Lens
import Data.Generics.Product
type API = API.API :<|> "static" :> Raw
server :: App -> Application
server app = serve api (enter server' API.handler :<|> serveDirectoryFileServer "static")
server app = serveWithContext api cfg (enter server' API.handler :<|> serveDirectoryFileServer "static")
where
myKey = view (field @"jwk") app
jwtCfg = defaultJWTSettings myKey
authCfg = Users.authCheck app
cfg = jwtCfg :. defaultCookieSettings :. authCfg :. EmptyContext
server' :: AppM :~> Servant.Handler
server' = NT (Handler . ExceptT . try . (`runReaderT` app) . (runFileLoggingT "logs/server.log"))
api :: Proxy API