Using curl to access backend API of Rails app that implements devise Using curl to access backend API of Rails app that implements devise curl curl

Using curl to access backend API of Rails app that implements devise


CSRF stands for Cross Site Request Forgery and is a security protection you can read more about here. Essentially rails generates a random token included in the form rendered on the page and it expects to get that token back on form submit. You don't need this protection for an api, but it is important for the web app side. See this question for methods to disable the CSRF token.

One approach you might take is to use the token_authenticable Devise module and authenticate your requests with auth_token=#{token}, then skip CSRF protection if an auth token is present.


Rails CSRF protection is preventing you from making this request.

From rails documentation

CSRF protection automatically include a security token, calculated from the current session and the server-side secret, in all forms and Ajax requests generated by Rails. You won't need the secret, if you use CookieStorage as session storage. If the security token doesn't match what was expected, the session will be reset. Note: In Rails versions prior to 3.0.4, this raised an ActionController::InvalidAuthenticityToken error.

If you want to skip it, add this line to your controller

skip_before_action :verify_authenticity_token, :only => ["your_update_action"]


You're missing a CSRF token. This is to prevent cross site request forgery.