简体   繁体   English

Rails使用curl设计登录

[英]Rails Devise login using curl

I'm trying to login to devise using curl as follows: 我正在尝试使用curl登录设计如下:

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: rails服务器日志显示:

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? 是否有可能获得CSRF令牌真实性并将其传递给sign_in请求以使用设计成功登录?

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. 我建议你不要使用curl并使用mechanize因为当你首先调用登录表单时它会自动处理这些东西。

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. 当你想继续使用curl时,你需要先调用登录页面并启用cookiejar选项来存储下次调用的会话。 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. 但是这个问题不是专门设计它的Rails的机制来不接受没有令牌发送的形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM