This includes a good set of default language extensions that are often used by us. It frees us of explicitly importing common extensions. Ref: https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/control.html#extension-GHC2021 Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
33 lines
1.2 KiB
Haskell
33 lines
1.2 KiB
Haskell
{-|
|
|
Module : PostgREST.Auth
|
|
Description : PostgREST authentication functions.
|
|
|
|
This module provides functions to deal with the JWT authentication (http://jwt.io).
|
|
It also can be used to define other authentication functions,
|
|
in the future Oauth, LDAP and similar integrations can be coded here.
|
|
|
|
Authentication should always be implemented in an external service.
|
|
In the test suite there is an example of simple login function that can be used for a
|
|
very simple authentication system inside the PostgreSQL database.
|
|
-}
|
|
module PostgREST.Auth
|
|
( getAuthResult )
|
|
where
|
|
|
|
import PostgREST.AppState (AppState, getConfig, getJwtCacheState, getTime)
|
|
import PostgREST.Auth.Jwt (parseClaims)
|
|
import PostgREST.Auth.JwtCache (lookupJwtCache)
|
|
import PostgREST.Auth.Types (AuthResult)
|
|
import PostgREST.Error (Error)
|
|
|
|
import Protolude
|
|
|
|
-- | Perform authentication and authorization
|
|
-- Parse JWT and return AuthResult
|
|
getAuthResult :: (MonadError Error m, MonadIO m) => AppState -> Maybe ByteString -> m AuthResult
|
|
getAuthResult appState token = do
|
|
conf <- liftIO $ getConfig appState
|
|
time <- liftIO $ getTime appState
|
|
|
|
parseClaims conf time =<< lookupJwtCache (getJwtCacheState appState) token
|