Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Devise login using curl

I'm trying to login to devise using curl as follows:

curl -v -b cookie.file -c cookie.file -H "Content-Type: application/json" -X POST -d '{"user" : {"email":"MYUSER" , "password":"MYPASSWORD" }}' <code>http://localhost:3000/users/sign_in.json<code>

The rails server logs shows:

WARNING: Can't verify CSRF token authenticity

Is it possible to get CSRF token authenticity and pass it to the sign_in request to login successfully using devise?

like image 913
random Avatar asked Nov 19 '25 23:11

random


1 Answers

I would suggest you not to use curl and use mechanize instead because it handels this stuff automaticly when you call the login form first.

When you want to go on using curl you need to call the login page first and enable the cookiejar option to store the session for the next call. Then you could add the token so you can login. But this problem isnt specific to devise its a mecanism of Rails to not accept forms that were sent without the token.

like image 193
davidb Avatar answered Nov 22 '25 01:11

davidb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!