我的rails应用程序订阅外部系统POST通知(名为Orion上下文代理)。我管理发送json数据&过程响应(ruby->猎户座)。
但是当收到通知请求时,我会收到InvalidAuthenticityToken错误无法验证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 ,但绝对寻找一种方法来管理这些不同服务之间的身份验证。
由于
答案 0 :(得分:2)
如果您知道自己在做什么,可以禁用CSRF保护!只要确保你没有为整个网站禁用它
在控制器中使用类似skip_before_action :verify_authenticity_token
的内容来重现这些帖子请求。