I want to test my rails web service using cURL, yet so far I could only do it while deactivating before_filter :authenticate_user!
. But I'd like to log in a priori and then create, destroy etc.
I saw that with cURL you can authenticate and save the session info in a cookie, that you use for your following requests, yet I couldn't make it work with Devise: in my scenario, the user logs in using an email/password combination, so I'm trying:
curl \ -X POST \ -d '[email protected]&password=password' \ -c cookie \ http://localhost:3000/users/sign_in > out
and I get: ActionController::InvalidAuthenticityToken in Devise/sessionsController#create
Could somebody give me an idea / an example?
Thanks!
This works:
Authenticate:
curl -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -X POST http://localhost:3000/users/sign_in \ -d "{'user' : { 'email' : '[email protected]', 'password' : 'password'}}" \ -c cookie
Show:
curl -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -X GET http://localhost:3000/pages/1.xml \ -b cookie
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With