i trying make basic auth api in clojure friend.
here login request :
curl -x post -h "content-type: application/x-www-form-urlencoded" -d 'user=myuser%40email.com&pass=super-secret-password' http://localhost:3000/login/
i using compojure well, i'm not sure how reuse linked example. here parts don't know how change :
how replace username/password fields user/pass fields in curl request ? able extract them raw request, don't know how pass friend (do need change
credential-fn
?).replace user atom data database. have
auth [email password]
returns true or false (fetching database , using bcrypt). can fetch user role database. how use database (specifically use mongo/monger) instead of user atom ?
you can provide totally different credential-fn, or stick demo credential-fn implemented using cemerick.friend.credentials/bcrypt-credential-fn. read doc of bcrypt-credential-fn @ https://github.com/cemerick/friend/blob/master/src/cemerick/friend/credentials.clj, quite long. expects load-credentials-fn loads user given username string, checks if password matches. in demo, load-credentials-fn map in users atom, if have database want provide different load-credentials-fn function lookup database, don't want load users table in map in atom.
Comments
Post a Comment