{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
module Auth.Biscuit.Servant
(
RequireBiscuit
, authHandler
, genBiscuitCtx
, authHandlerWith
, genBiscuitCtxWith
, BiscuitConfig (..)
, defaultBiscuitConfig
, checkBiscuit
, checkBiscuitM
, checkBiscuitWith
, checkBiscuitMWith
, WithAuthorizer' (..)
, WithAuthorizer
, handleBiscuit
, handleBiscuitWith
, withAuthorizer
, withAuthorizer_
, withAuthorizerM
, withAuthorizerM_
, noAuthorizer
, noAuthorizer_
, withFallbackAuthorizer
, withPriorityAuthorizer
, withFallbackAuthorizerM
, withPriorityAuthorizerM
, withTransformation
, module Biscuit
) where
import Auth.Biscuit as Biscuit
import Control.Applicative (liftA2)
import Control.Monad.Except (MonadError, throwError)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Reader (ReaderT (..), lift,
runReaderT, withReaderT)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as C8
import qualified Data.ByteString.Lazy as LBS
import Data.Either (fromRight)
import Data.Kind (Type)
import Network.Wai
import Servant (AuthProtect)
import Servant.Server
import Servant.Server.Experimental.Auth
type RequireBiscuit = AuthProtect "biscuit"
type instance AuthServerData RequireBiscuit = Biscuit OpenOrSealed Verified
data WithAuthorizer' (t :: Type) (m :: Type -> Type) (a :: Type)
= WithAuthorizer
{ forall t (m :: * -> *) a. WithAuthorizer' t m a -> ReaderT t m a
handler_ :: ReaderT t m a
, forall t (m :: * -> *) a. WithAuthorizer' t m a -> m Authorizer
authorizer_ :: m Authorizer
}
type WithAuthorizer = WithAuthorizer' (AuthorizedBiscuit OpenOrSealed)
withFallbackAuthorizer :: Functor m
=> Authorizer
-> WithAuthorizer' t m a
-> WithAuthorizer' t m a
withFallbackAuthorizer :: forall (m :: * -> *) t a.
Functor m =>
Authorizer -> WithAuthorizer' t m a -> WithAuthorizer' t m a
withFallbackAuthorizer Authorizer
newV h :: WithAuthorizer' t m a
h@WithAuthorizer{m Authorizer
authorizer_ :: m Authorizer
authorizer_ :: forall t (m :: * -> *) a. WithAuthorizer' t m a -> m Authorizer
authorizer_} =
WithAuthorizer' t m a
h { authorizer_ :: m Authorizer
authorizer_ = (forall a. Semigroup a => a -> a -> a
<> Authorizer
newV) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Authorizer
authorizer_ }
withFallbackAuthorizerM :: Applicative m
=> m Authorizer
-> WithAuthorizer' t m a
-> WithAuthorizer' t m a
withFallbackAuthorizerM :: forall (m :: * -> *) t a.
Applicative m =>
m Authorizer -> WithAuthorizer' t m a -> WithAuthorizer' t m a
withFallbackAuthorizerM m Authorizer
newV h :: WithAuthorizer' t m a
h@WithAuthorizer{m Authorizer
authorizer_ :: m Authorizer
authorizer_ :: forall t (m :: * -> *) a. WithAuthorizer' t m a -> m Authorizer
authorizer_} =
WithAuthorizer' t m a
h { authorizer_ :: m Authorizer
authorizer_ = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Semigroup a => a -> a -> a
(<>) m Authorizer
authorizer_ m Authorizer
newV }
withPriorityAuthorizer :: Functor m
=> Authorizer
-> WithAuthorizer m a
-> WithAuthorizer m a
withPriorityAuthorizer :: forall (m :: * -> *) a.
Functor m =>
Authorizer -> WithAuthorizer m a -> WithAuthorizer m a
withPriorityAuthorizer Authorizer
newV h :: WithAuthorizer m a
h@WithAuthorizer{m Authorizer
authorizer_ :: m Authorizer
authorizer_ :: forall t (m :: * -> *) a. WithAuthorizer' t m a -> m Authorizer
authorizer_} =
WithAuthorizer m a
h { authorizer_ :: m Authorizer
authorizer_ = (Authorizer
newV forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Authorizer
authorizer_ }
withPriorityAuthorizerM :: Applicative m
=> m Authorizer
-> WithAuthorizer' t m a
-> WithAuthorizer' t m a
withPriorityAuthorizerM :: forall (m :: * -> *) t a.
Applicative m =>
m Authorizer -> WithAuthorizer' t m a -> WithAuthorizer' t m a
withPriorityAuthorizerM m Authorizer
newV h :: WithAuthorizer' t m a
h@WithAuthorizer{m Authorizer
authorizer_ :: m Authorizer
authorizer_ :: forall t (m :: * -> *) a. WithAuthorizer' t m a -> m Authorizer
authorizer_} =
WithAuthorizer' t m a
h { authorizer_ :: m Authorizer
authorizer_ = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Semigroup a => a -> a -> a
(<>) m Authorizer
newV m Authorizer
authorizer_ }
withAuthorizer :: Applicative m
=> Authorizer
-> ReaderT t m a
-> WithAuthorizer' t m a
withAuthorizer :: forall (m :: * -> *) t a.
Applicative m =>
Authorizer -> ReaderT t m a -> WithAuthorizer' t m a
withAuthorizer Authorizer
v ReaderT t m a
handler_ =
WithAuthorizer
{ ReaderT t m a
handler_ :: ReaderT t m a
handler_ :: ReaderT t m a
handler_
, authorizer_ :: m Authorizer
authorizer_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure Authorizer
v
}
withAuthorizerM :: m Authorizer
-> ReaderT t m a
-> WithAuthorizer' t m a
withAuthorizerM :: forall (m :: * -> *) t a.
m Authorizer -> ReaderT t m a -> WithAuthorizer' t m a
withAuthorizerM m Authorizer
authorizer_ ReaderT t m a
handler_ =
WithAuthorizer
{ ReaderT t m a
handler_ :: ReaderT t m a
handler_ :: ReaderT t m a
handler_
, m Authorizer
authorizer_ :: m Authorizer
authorizer_ :: m Authorizer
authorizer_
}
withAuthorizer_ :: Monad m => Authorizer -> m a -> WithAuthorizer' t m a
withAuthorizer_ :: forall (m :: * -> *) a t.
Monad m =>
Authorizer -> m a -> WithAuthorizer' t m a
withAuthorizer_ Authorizer
v = forall (m :: * -> *) t a.
Applicative m =>
Authorizer -> ReaderT t m a -> WithAuthorizer' t m a
withAuthorizer Authorizer
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
withAuthorizerM_ :: Monad m => m Authorizer -> m a -> WithAuthorizer' t m a
withAuthorizerM_ :: forall (m :: * -> *) a t.
Monad m =>
m Authorizer -> m a -> WithAuthorizer' t m a
withAuthorizerM_ m Authorizer
v = forall (m :: * -> *) t a.
m Authorizer -> ReaderT t m a -> WithAuthorizer' t m a
withAuthorizerM m Authorizer
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
noAuthorizer :: Applicative m
=> ReaderT t m a
-> WithAuthorizer' t m a
noAuthorizer :: forall (m :: * -> *) t a.
Applicative m =>
ReaderT t m a -> WithAuthorizer' t m a
noAuthorizer = forall (m :: * -> *) t a.
Applicative m =>
Authorizer -> ReaderT t m a -> WithAuthorizer' t m a
withAuthorizer forall a. Monoid a => a
mempty
noAuthorizer_ :: Monad m => m a -> WithAuthorizer' t m a
noAuthorizer_ :: forall (m :: * -> *) a t. Monad m => m a -> WithAuthorizer' t m a
noAuthorizer_ = forall (m :: * -> *) t a.
Applicative m =>
ReaderT t m a -> WithAuthorizer' t m a
noAuthorizer forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
data BiscuitConfig e
= BiscuitConfig
{ forall e. BiscuitConfig e -> ParserConfig Handler
parserConfig :: ParserConfig Handler
, :: Request -> Either e ByteString
, :: forall a. e -> Handler a
, forall e. BiscuitConfig e -> forall a. ParseError -> Handler a
onParseError :: forall a. ParseError -> Handler a
}
defaultBiscuitConfig :: PublicKey -> BiscuitConfig String
defaultBiscuitConfig :: PublicKey -> BiscuitConfig String
defaultBiscuitConfig PublicKey
publicKey = BiscuitConfig
{ parserConfig :: ParserConfig Handler
parserConfig = ParserConfig
{ getPublicKey :: Maybe Int -> PublicKey
getPublicKey = forall a b. a -> b -> a
const PublicKey
publicKey
, isRevoked :: Set ByteString -> Handler Bool
isRevoked = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
, encoding :: BiscuitEncoding
encoding = BiscuitEncoding
UrlBase64
}
, extractSerializedBiscuit :: Request -> Either String ByteString
extractSerializedBiscuit = Request -> Either String ByteString
readFromAuthHeader
, onExtractionError :: forall a. String -> Handler a
onExtractionError = forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either ParseError String -> ServerError
defaultInvalidBiscuitError forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. b -> Either a b
Right
, onParseError :: forall a. ParseError -> Handler a
onParseError = forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either ParseError String -> ServerError
defaultInvalidBiscuitError forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left
}
readFromAuthHeader :: Request -> Either String ByteString
Request
req = do
let note :: a -> Maybe b -> Either a b
note a
e = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a b. a -> Either a b
Left a
e) forall a b. b -> Either a b
Right
ByteString
authHeader <- forall {a} {b}. a -> Maybe b -> Either a b
note String
"Missing Authorization header" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup HeaderName
"Authorization" forall a b. (a -> b) -> a -> b
$ Request -> RequestHeaders
requestHeaders Request
req
forall {a} {b}. a -> Maybe b -> Either a b
note String
"Not a Bearer token" forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString -> Maybe ByteString
BS.stripPrefix ByteString
"Bearer " ByteString
authHeader
defaultInvalidBiscuitError :: Either ParseError String -> ServerError
defaultInvalidBiscuitError :: Either ParseError String -> ServerError
defaultInvalidBiscuitError Either ParseError String
e =
let s :: String
s = forall b a. b -> Either a b -> b
fromRight String
"Not a B64-encoded biscuit" Either ParseError String
e
in ServerError
err401 { errBody :: ByteString
errBody = ByteString -> ByteString
LBS.fromStrict (String -> ByteString
C8.pack String
s) }
defaultUnauthorizedBiscuitError :: ExecutionError -> ServerError
defaultUnauthorizedBiscuitError :: ExecutionError -> ServerError
defaultUnauthorizedBiscuitError ExecutionError
_ =
ServerError
err403 { errBody :: ByteString
errBody = ByteString
"Biscuit failed checks" }
authHandlerWith :: BiscuitConfig e
-> AuthHandler Request (Biscuit OpenOrSealed Verified)
authHandlerWith :: forall e.
BiscuitConfig e
-> AuthHandler Request (Biscuit OpenOrSealed Verified)
authHandlerWith BiscuitConfig{ParserConfig Handler
Request -> Either e ByteString
forall a. e -> Handler a
forall a. ParseError -> Handler a
onParseError :: forall a. ParseError -> Handler a
onExtractionError :: forall a. e -> Handler a
extractSerializedBiscuit :: Request -> Either e ByteString
parserConfig :: ParserConfig Handler
onParseError :: forall e. BiscuitConfig e -> forall a. ParseError -> Handler a
onExtractionError :: forall e. BiscuitConfig e -> forall a. e -> Handler a
extractSerializedBiscuit :: forall e. BiscuitConfig e -> Request -> Either e ByteString
parserConfig :: forall e. BiscuitConfig e -> ParserConfig Handler
..} = forall r usr. (r -> Handler usr) -> AuthHandler r usr
mkAuthHandler Request -> Handler (Biscuit OpenOrSealed Verified)
handler
where
orExtractionError :: Either e ByteString -> Handler ByteString
orExtractionError = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. e -> Handler a
onExtractionError forall (f :: * -> *) a. Applicative f => a -> f a
pure
orParseError :: Either ParseError (Biscuit OpenOrSealed Verified)
-> Handler (Biscuit OpenOrSealed Verified)
orParseError = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. ParseError -> Handler a
onParseError forall (f :: * -> *) a. Applicative f => a -> f a
pure
handler :: Request -> Handler (Biscuit OpenOrSealed Verified)
handler Request
req = do
ByteString
bs <- Either e ByteString -> Handler ByteString
orExtractionError forall a b. (a -> b) -> a -> b
$ Request -> Either e ByteString
extractSerializedBiscuit Request
req
Either ParseError (Biscuit OpenOrSealed Verified)
-> Handler (Biscuit OpenOrSealed Verified)
orParseError forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *).
Applicative m =>
ParserConfig m
-> ByteString
-> m (Either ParseError (Biscuit OpenOrSealed Verified))
parseWith ParserConfig Handler
parserConfig ByteString
bs
authHandler :: PublicKey -> AuthHandler Request (Biscuit OpenOrSealed Verified)
authHandler :: PublicKey -> AuthHandler Request (Biscuit OpenOrSealed Verified)
authHandler = forall e.
BiscuitConfig e
-> AuthHandler Request (Biscuit OpenOrSealed Verified)
authHandlerWith forall b c a. (b -> c) -> (a -> b) -> a -> c
. PublicKey -> BiscuitConfig String
defaultBiscuitConfig
genBiscuitCtx :: PublicKey
-> Context '[AuthHandler Request (Biscuit OpenOrSealed Verified)]
genBiscuitCtx :: PublicKey
-> Context '[AuthHandler Request (Biscuit OpenOrSealed Verified)]
genBiscuitCtx PublicKey
pk = PublicKey -> AuthHandler Request (Biscuit OpenOrSealed Verified)
authHandler PublicKey
pk forall x (xs :: [*]). x -> Context xs -> Context (x : xs)
:. Context '[]
EmptyContext
genBiscuitCtxWith :: BiscuitConfig e
-> Context '[AuthHandler Request (Biscuit OpenOrSealed Verified)]
genBiscuitCtxWith :: forall e.
BiscuitConfig e
-> Context '[AuthHandler Request (Biscuit OpenOrSealed Verified)]
genBiscuitCtxWith BiscuitConfig e
c = forall e.
BiscuitConfig e
-> AuthHandler Request (Biscuit OpenOrSealed Verified)
authHandlerWith BiscuitConfig e
c forall x (xs :: [*]). x -> Context xs -> Context (x : xs)
:. Context '[]
EmptyContext
checkBiscuit :: (MonadIO m, MonadError ServerError m)
=> Biscuit OpenOrSealed Verified
-> Authorizer
-> m a
-> m a
checkBiscuit :: forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
Biscuit OpenOrSealed Verified -> Authorizer -> m a -> m a
checkBiscuit Biscuit OpenOrSealed Verified
vb = do
forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
Biscuit OpenOrSealed Verified -> m Authorizer -> m a -> m a
checkBiscuitM Biscuit OpenOrSealed Verified
vb forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure
checkBiscuitWith :: (MonadIO m, MonadError ServerError m)
=> (forall b. ExecutionError -> m b)
-> Biscuit OpenOrSealed Verified
-> Authorizer
-> ReaderT (AuthorizedBiscuit OpenOrSealed) m a
-> m a
checkBiscuitWith :: forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
(forall b. ExecutionError -> m b)
-> Biscuit OpenOrSealed Verified
-> Authorizer
-> ReaderT (AuthorizedBiscuit OpenOrSealed) m a
-> m a
checkBiscuitWith forall b. ExecutionError -> m b
onError Biscuit OpenOrSealed Verified
vb =
forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
(forall b. ExecutionError -> m b)
-> Biscuit OpenOrSealed Verified
-> m Authorizer
-> ReaderT (AuthorizedBiscuit OpenOrSealed) m a
-> m a
checkBiscuitMWith forall b. ExecutionError -> m b
onError Biscuit OpenOrSealed Verified
vb forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure
checkBiscuitM :: (MonadIO m, MonadError ServerError m)
=> Biscuit OpenOrSealed Verified
-> m Authorizer
-> m a
-> m a
checkBiscuitM :: forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
Biscuit OpenOrSealed Verified -> m Authorizer -> m a -> m a
checkBiscuitM Biscuit OpenOrSealed Verified
vb m Authorizer
mv m a
h = do
let onError :: ExecutionError -> m a
onError = forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExecutionError -> ServerError
defaultUnauthorizedBiscuitError
in forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
(forall b. ExecutionError -> m b)
-> Biscuit OpenOrSealed Verified
-> m Authorizer
-> ReaderT (AuthorizedBiscuit OpenOrSealed) m a
-> m a
checkBiscuitMWith forall {a}. ExecutionError -> m a
onError Biscuit OpenOrSealed Verified
vb m Authorizer
mv (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m a
h)
checkBiscuitMWith :: (MonadIO m, MonadError ServerError m)
=> (forall b. ExecutionError -> m b)
-> Biscuit OpenOrSealed Verified
-> m Authorizer
-> ReaderT (AuthorizedBiscuit OpenOrSealed) m a
-> m a
checkBiscuitMWith :: forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
(forall b. ExecutionError -> m b)
-> Biscuit OpenOrSealed Verified
-> m Authorizer
-> ReaderT (AuthorizedBiscuit OpenOrSealed) m a
-> m a
checkBiscuitMWith forall b. ExecutionError -> m b
onError Biscuit OpenOrSealed Verified
vb m Authorizer
mv ReaderT (AuthorizedBiscuit OpenOrSealed) m a
h = do
Authorizer
v <- m Authorizer
mv
Either ExecutionError (AuthorizedBiscuit OpenOrSealed)
res <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall proof.
Biscuit proof Verified
-> Authorizer
-> IO (Either ExecutionError (AuthorizedBiscuit proof))
authorizeBiscuit Biscuit OpenOrSealed Verified
vb Authorizer
v
case Either ExecutionError (AuthorizedBiscuit OpenOrSealed)
res of
Left ExecutionError
e -> forall b. ExecutionError -> m b
onError ExecutionError
e
Right AuthorizedBiscuit OpenOrSealed
as -> forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT (AuthorizedBiscuit OpenOrSealed) m a
h AuthorizedBiscuit OpenOrSealed
as
handleBiscuit :: (MonadIO m, MonadError ServerError m)
=> Biscuit OpenOrSealed Verified
-> WithAuthorizer m a
-> m a
handleBiscuit :: forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
Biscuit OpenOrSealed Verified -> WithAuthorizer m a -> m a
handleBiscuit Biscuit OpenOrSealed Verified
b WithAuthorizer{m Authorizer
authorizer_ :: m Authorizer
authorizer_ :: forall t (m :: * -> *) a. WithAuthorizer' t m a -> m Authorizer
authorizer_, ReaderT (AuthorizedBiscuit OpenOrSealed) m a
handler_ :: ReaderT (AuthorizedBiscuit OpenOrSealed) m a
handler_ :: forall t (m :: * -> *) a. WithAuthorizer' t m a -> ReaderT t m a
handler_} =
let onError :: ExecutionError -> m a
onError = forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExecutionError -> ServerError
defaultUnauthorizedBiscuitError
in forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
(forall b. ExecutionError -> m b)
-> Biscuit OpenOrSealed Verified
-> m Authorizer
-> ReaderT (AuthorizedBiscuit OpenOrSealed) m a
-> m a
checkBiscuitMWith forall {a}. ExecutionError -> m a
onError Biscuit OpenOrSealed Verified
b m Authorizer
authorizer_ ReaderT (AuthorizedBiscuit OpenOrSealed) m a
handler_
handleBiscuitWith :: (MonadIO m, MonadError ServerError m)
=> (forall b. ExecutionError -> m b)
-> Biscuit OpenOrSealed Verified
-> WithAuthorizer m a
-> m a
handleBiscuitWith :: forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
(forall b. ExecutionError -> m b)
-> Biscuit OpenOrSealed Verified -> WithAuthorizer m a -> m a
handleBiscuitWith forall b. ExecutionError -> m b
onError Biscuit OpenOrSealed Verified
b WithAuthorizer{m Authorizer
authorizer_ :: m Authorizer
authorizer_ :: forall t (m :: * -> *) a. WithAuthorizer' t m a -> m Authorizer
authorizer_, ReaderT (AuthorizedBiscuit OpenOrSealed) m a
handler_ :: ReaderT (AuthorizedBiscuit OpenOrSealed) m a
handler_ :: forall t (m :: * -> *) a. WithAuthorizer' t m a -> ReaderT t m a
handler_} =
forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
(forall b. ExecutionError -> m b)
-> Biscuit OpenOrSealed Verified
-> m Authorizer
-> ReaderT (AuthorizedBiscuit OpenOrSealed) m a
-> m a
checkBiscuitMWith forall b. ExecutionError -> m b
onError Biscuit OpenOrSealed Verified
b m Authorizer
authorizer_ ReaderT (AuthorizedBiscuit OpenOrSealed) m a
handler_
withTransformation :: Monad m
=> (t -> m t')
-> WithAuthorizer' t' m a
-> WithAuthorizer' t m a
withTransformation :: forall (m :: * -> *) t t' a.
Monad m =>
(t -> m t') -> WithAuthorizer' t' m a -> WithAuthorizer' t m a
withTransformation t -> m t'
compute wa :: WithAuthorizer' t' m a
wa@WithAuthorizer{ReaderT t' m a
handler_ :: ReaderT t' m a
handler_ :: forall t (m :: * -> *) a. WithAuthorizer' t m a -> ReaderT t m a
handler_} =
let newHandler :: ReaderT t m a
newHandler = do
t'
t' <- forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT t -> m t'
compute
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall a b. a -> b -> a
const t'
t') ReaderT t' m a
handler_
in WithAuthorizer' t' m a
wa { handler_ :: ReaderT t m a
handler_ = ReaderT t m a
newHandler }