我有一个Rails应用程序App2
侦听端口4000的API调用和另一个Rails应用程序App1
侦听端口3000 App2
有定义的自定义API调用只能由经过认证的用户进行使用, 。无法使从Rake任务
rake任务是在App1
跑,它使用HTTParty使API请求为:
response = HTTParty.post("http://localhost:4000/users/sign_in",
:basic_auth => {:user => {:email => "<User email>", :password => "<Password>"}},
:headers => { 'X-Requested-With' => 'XMLHttpRequest',
'User-Agent' => 'Mozilla/5.0 (iPhone; U; ru; CPU iPhone OS 4_2_1 like Mac OS X; ru) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5',
'ContentType' => 'application/json' })
的response.body
输出显示的用户没有通过验证!
在分析错误,开发日志显示:
WARNING: Can't verify CSRF token authenticity
请帮我如何从Rake任务POST请求发送CSRF令牌。
有没有什么办法让我可以跳过基于我在rake任务请求传递参数的'protect_from_forgery'检查? – SriramK89
看看'skip_before_action:verify_authenticity_token'和你可以用来配置它的参数 – phoet