rails - “WARNING: Can't verify CSRF token authenticity” for json devise requests

前端 未结 10 2172
终归单人心
终归单人心 2020-11-27 10:11

How can I retrieve the CSRF token to pass with a JSON request?

I know that for security reasons Rails is checking the CSRF token on all the request types (including

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 10:30

    I have used the below. Using include? so if the content type is application/json;charset=utf-8 then it is still working.

    protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format.include? 'application/json' }
    

提交回复
热议问题