我的rails应用程序订阅了一个外部系统POST通知(名为Orion上下文代理)。我管理发送json数据&过程响应(ruby->猎户座)。
但当收到通知请求时,我会收到InvalidAuthentityToken错误无法验证CSRF令牌的真实性警告。
I, [2015-12-03T16:56:53.215991 #22189] INFO -- : Started POST "/machine/listen" for 127.0.0.1 at 2015-12-03 16:56:53 +0000
I, [2015-12-03T16:56:53.221524 #22189] INFO -- : Processing by MachineController#listen as XML
I, [2015-12-03T16:56:53.221762 #22189] INFO -- : Parameters: {"subscriptionId"=>"5660745482ef938cd5055ae3", "originator"=>"localhost", "contextResponses"=>[{"contextElement"=>{"type"=>"Printer", "isPattern"=>"false", "id"=>"UM1", "attributes"=>[{"name"=>"temperature", "type"=>"float", "value"=>"110"}]}, "statusCode"=>{"code"=>"200", "reasonPhrase"=>"OK"}}], "machine"=>{"subscriptionId"=>"5660745482ef938cd5055ae3", "originator"=>"localhost", "contextResponses"=>[{"contextElement"=>{"type"=>"Printer", "isPattern"=>"false", "id"=>"UM1", "attributes"=>[{"name"=>"temperature", "type"=>"float", "value"=>"110"}]}, "statusCode"=>{"code"=>"200", "reasonPhrase"=>"OK"}}]}}
W, [2015-12-03T16:56:53.223637 #22189] WARN -- : Can't verify CSRF token authenticity
I, [2015-12-03T16:56:53.224191 #22189] INFO -- : Completed 422 Unprocessable Entity in 2ms (ActiveRecord: 0.0ms)
F, [2015-12-03T16:56:53.225189 #22189] FATAL -- :
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
我知道发送回(Orion->ruby)的消息不包含正确的安全令牌。
也许我可以禁用protect_from_forgery,但明确地寻找一种方法来管理这些不同服务之间的身份验证。
感谢
如果你知道自己在做什么,可以禁用CSRF保护!只要确保你没有禁用它为你的整个网站
在接收这些post请求的控制器中使用类似skip_before_action :verify_authenticity_token
的东西。