As party of my effort to quickly hack a LDAP auth solution, I thought I can replace Auth.loginUser with my implementation and get it working. I did this experiment. Replacing Auth.loginUser in the "snap init" example with a dummy myLoginUser which already returns AuthUser. I was expecting this will allow any user to login, but it does not and redirect me to login page without error.
What is wrong here?
ldapAuth :: ByteString -> ByteString -> Handler b (AuthManager b) (Either AuthFailure AuthUser)
ldapAuth username password = do { ld <- liftIO (ldapInit hostname port)
; liftIO (putStrLn ("ldapAuth is called with" ++ (BC.unpack username) ++ " and " ++ (BC.unpack password)))
; return $ Right (defAuthUser { userLogin = T.pack $ BC.unpack username })
}
myLoginUser
:: ByteString
-- ^ Username field
-> ByteString
-- ^ Password field
-> Maybe ByteString
-- ^ Remember field; Nothing if you want no remember function.
-> (AuthFailure -> Handler b (AuthManager b) ())
-- ^ Upon failure
-> Handler b (AuthManager b) ()
-- ^ Upon success
-> Handler b (AuthManager b) ()
myLoginUser unf pwdf remf loginFail loginSucc =
runErrorT go >>= either loginFail (const loginSucc)
where
go :: ErrorT AuthFailure (Handler b (AuthManager b)) AuthUser
go = do { mbUsername <- getParam unf
; mbPassword <- getParam pwdf
; password <- maybe (throwError PasswordMissing) return mbPassword
; username <- maybe (fail "Username is missing") return mbUsername
; ErrorT $ ldapAuth username password
}
Thanks,
Neal