return user data at user end point based on token id
This commit is contained in:
parent
2716ccf2c0
commit
c8835c1d45
@ -14,7 +14,7 @@ import Control.Concurrent
|
||||
import Control.Concurrent.STM (atomically)
|
||||
import Control.Concurrent.STM.TVar (newTVarIO, readTVar, modifyTVar)
|
||||
import Control.Exception (bracket)
|
||||
import Control.Monad (unless)
|
||||
import Control.Monad (unless, (>=>))
|
||||
import Control.Monad.IO.Class
|
||||
import Control.Monad.Trans.Reader
|
||||
|
||||
@ -261,12 +261,11 @@ userEndpoint = handleUserData
|
||||
let jwt = fromJust . decode @JWT $ fromStrict body
|
||||
-- TODO check if token grants access, then read logged in user from cookie
|
||||
liftIO $ print jwt
|
||||
return mempty
|
||||
-- let
|
||||
-- scopes' = map (readScope @user @userData) $ words scopes
|
||||
-- uData = mconcat $ map (userScope @user @userData u) scopes'
|
||||
-- liftIO . putStrLn $ "user: " ++ show u ++ " | scopes: " ++ show (map (showScope @user @userData) scopes')
|
||||
-- return uData
|
||||
mUser <- ask >>= liftIO . (atomically . readTVar >=> return . Map.lookup (jti jwt) . activeTokens)
|
||||
case mUser of
|
||||
Just (u, scopes) -> return . mconcat $ map (userScope @user @userData u) scopes
|
||||
Nothing -> throwError $ err500 { errBody = "Unknown token" }
|
||||
|
||||
|
||||
decodeToken :: forall user userData . UserData user userData => Text -> AuthState user -> IO (Either JwtError JwtContent)
|
||||
decodeToken token state = do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user