I wrote a post that tries to explain all the crazy cases you need to handle to dispatch Friend responses based on content type:

http://sritchie.github.io/2014/01/17/api-authentication-with-liberator-and-friend/

Liberator can be helpful for this.

Ivan Schuetz <mailto:ivanschu...@gmail.com>
April 23, 2014 3:28 PM
Hi,

I'm trying to get a simple use case running - send a login request to /login and get success or fail response, preferably in JSON format.

I followed the example in https://github.com/cemerick/friend#workflows <https://github.com/cemerick/friend#workflows>


(def users {"root" {:username "root"
                    :password (creds/hash-bcrypt "admin_password")
                    :roles #{::admin}}
            "jane" {:username "jane"
                    :password (creds/hash-bcrypt "test")
                    :roles #{::user}}})


(defroutes app-routes

  (GET "/test" [] {:body {:my-map "helo"}})
  (route/resources "/")
  (route/not-found "Not found"))

(def app
  (->
      (handler/api app-routes)
      (middleware/wrap-json-body)
      (middleware/wrap-json-response)

(friend/authenticate {:credential-fn (partial creds/bcrypt-credential-fn users)
                            :workflows [
                                        (workflows/interactive-form)]})
      )
  )



I'm testing with curl:

curl -v --data "username=jane&password=test" http://localhost:3000/login

Or:

curl -v --request POST "http://localhost:3000/login?username=jane&password=test <http://localhost:3000/login?username=jane&password=test>"

And I get:

* About to connect() to localhost port 3000 (#0)
*   Trying ::1...
* connected
* Connected to localhost (::1) port 3000 (#0)
> POST /login?username=jane&password=test HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
> Host: localhost:3000
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Wed, 23 Apr 2014 22:25:15 GMT
< Location: http://localhost:3000/login?&login_failed=Y&username= <http://localhost:3000/login?&login_failed=Y&username=>
< Content-Length: 0
< Server: Jetty(7.6.8.v20121106)
<
* Connection #0 to host localhost left intact
* Closing connection #0


This looks like authentication failed, but the data is correct. I reviewed the curl request, and this seems to be the correct way to send a POST. But &username= gives me the impression it's not being parsed correctly.

Also, how can I get a JSON response instead of only a header?

Thanks.

P.S. Maybe it would be positive if this library has an own Google Group.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com <mailto:clojure+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

--
Sam Ritchie (@sritchie)
Paddleguru Co-Founder
703.863.8561
www.paddleguru.com <http://www.paddleguru.com/>
Twitter <http://twitter.com/paddleguru>// Facebook <http://facebook.com/paddleguru>

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to