Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm willing to open a PR to add JSON support to Yesod.Auth.Dummy #1618

3v0k4 opened this issue Aug 17, 2019 · 3 comments · Fixed by #1619


Copy link

commented Aug 17, 2019

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


This comment has been minimized.

Copy link

commented Aug 19, 2019


This comment has been minimized.

Copy link
Contributor Author

commented Aug 19, 2019

I'm on it. Thanks!

@3v0k4 3v0k4 referenced this issue Aug 19, 2019
5 of 5 tasks complete

This comment has been minimized.

Copy link

commented Aug 23, 2019

Thanks for the PR. Further discussion can be had on the PR itself, so I will close this issue.

@jezen jezen closed this Aug 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.