Last active
August 29, 2015 14:24
-
-
Save seanhess/68455122a39d0b2da6e5 to your computer and use it in GitHub Desktop.
error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AuthLookup = JWTClaimsSet -> Bool | |
data AuthProtected | |
protected :: AuthLookup -> server -> (AuthLookup, server) | |
protected look server = (look, server) | |
--instance (Enter typ arg ret) => Enter (AuthLookup, rest) where | |
--enter (al, rest) = enter rest | |
-- make it only allow an admin for now | |
instance HasServer rest => HasServer (AuthProtected :> rest) where | |
type ServerT (AuthProtected :> rest) m = (AuthLookup, ServerT rest m) | |
route Proxy (authLookup, a) request respond = do | |
case parseToken $ fmap decodeUtf8 $ lookup "Cookie" (requestHeaders request) of | |
Nothing -> respond . succeedWith $ responseLBS status401 [] "Missing cookie." | |
Just v -> do | |
mcs <- verifyClaims v | |
case mcs of | |
Nothing -> respond . succeedWith $ responseLBS status403 [] "Invalid auth token." | |
Just cs -> do | |
if authLookup cs | |
then route (Proxy :: Proxy rest) a request respond | |
else respond . succeedWith $ responseLBS status403 [] "Forbidden" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/Users/seanhess/projects/serials/server/Serials/Api.hs:251:24: | |
No instance for (Servant.Server.Internal.Enter.Enter | |
(AuthLookup, App [Char]) | |
(App :~> EitherT ServantErr IO) | |
(AuthLookup, EitherT ServantErr IO [Char])) | |
arising from a use of ‘enter’ | |
In the expression: enter (Nat $ (runAppT config)) exampleServerT | |
In an equation for ‘exampleServer’: | |
exampleServer config | |
= enter (Nat $ (runAppT config)) exampleServerT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ExampleAPI = AuthProtected :> Get String | |
exampleServerT :: ServerT ExampleAPI App | |
exampleServerT = protected hasClaimAdmin (hello) | |
where | |
hello = return "Hello" | |
exampleServer :: AppConfig -> Server ExampleAPI | |
exampleServer config = enter (Nat $ (runAppT config)) exampleServerT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment