provide data of authenticated user

This commit is contained in:
David Mosbach 2023-12-22 04:27:44 +01:00
parent 52f43c81eb
commit f47e0b7cb0

View File

@ -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