-
Notifications
You must be signed in to change notification settings - Fork 383
Closed
Description
From what I understand Yesod.Auth.Dummy does not support JSON parameters. In fact it uses runInputPost which I believe only takes care of POST parameters.
I've been playing with Haskell and Yesod for a few weeks while writing a series of blog posts. I wanted to have Yesod.Auth.Dummy play nice with both form submissions and API requests. That's why I patched Yesod.Auth.Dummy to something like this:
parser :: Value -> Parser Text
parser = withObject "ident" (\obj -> do
ident <- obj .: "ident"
return ident)
authDummy' :: YesodAuth m => AuthPlugin m
authDummy' =
AuthPlugin "dummy" dispatch login
where
dispatch "POST" [] = do
result <- runInputPostResult $ ireq textField "ident"
case result of
FormSuccess ident ->
setCredsRedirect $ Creds "dummy" ident []
_ -> do
(result :: Result Value) <- parseCheckJsonBody
case result of
Success val -> do
let mIdent = parseEither parser val
case mIdent of
Right ident ->
setCredsRedirect $ Creds "dummy" ident []
Left err ->
invalidArgs [T.pack err]
Error err ->
invalidArgs [T.pack err]
dispatch _ _ = notFound
url = PluginR "dummy" []
login authToMaster = do
request <- getRequest
toWidget [hamlet|
$newline never
<form method="post" action="@{authToMaster url}">
$maybe t <- reqToken request
<input type=hidden name=#{defaultCsrfParamName} value=#{t}>
Your new identifier is: #
<input type="text" name="ident">
<input type="submit" value="Dummy Login">
|]If anything I said above makes any sense, would you be willing to accept a PR to have Yesod.Auth.Dummy accepting JSON parameters? I'm ready to dig deeper and improve the code. Keep in mind, this would be my first PR in Haskell and Yesod, thus I'll prolly need some help.
Yesod is awesome, thanks for all your work!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels