From f47e0b7cb005afa462728b3a1c8b2480bf9aaa24 Mon Sep 17 00:00:00 2001 From: David Mosbach Date: Fri, 22 Dec 2023 04:27:44 +0100 Subject: [PATCH] provide data of authenticated user --- src/Server.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Server.hs b/src/Server.hs index 5e288c4..1a266ce 100644 --- a/src/Server.hs +++ b/src/Server.hs @@ -38,20 +38,20 @@ type Auth user userData = BasicAuth "login" user :> "auth" :> QueryParam "scopes type Token = "token" :> Post '[JSON] Text -- TODO post jwt token -- type Insert = "insert" :> Post '[JSON] User -authServer :: forall user userData . UserData user userData => [user] -> Server (Auth user userData) -authServer testUsers = handleAuth +authServer :: forall user userData . UserData user userData => Server (Auth user userData) +authServer = handleAuth where handleAuth :: user -> Maybe String -> Handler (Maybe userData) handleAuth _ Nothing = liftIO (putStrLn "no query param given") >> return Nothing - handleAuth _ (Just x) = do + handleAuth u (Just x) = do let scopes = readScopes @user @userData x - ud = mconcat $ map (userScope @user @userData $ head testUsers) scopes + ud = mconcat $ map (userScope @user @userData u) scopes liftIO (putStrLn $ "query param: " ++ showScopes @user @userData scopes) return $ Just ud exampleAuthServer :: Server (Auth User (Map.Map Text Text)) -exampleAuthServer = authServer testUsers +exampleAuthServer = authServer authAPI :: Proxy (Auth User (Map.Map Text Text)) authAPI = Proxy