Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't verify CSRF token authenticity when calling Rails from Android

I'm getting an "Can't verify CSRF token authenticity" when I try to use my android app to call the create action on one of the controllers in my rails service. Also says "Completed 422 Unprocessable Entity" after that. Any ideas what would cause that? Thanks.

like image 335
user3064141 Avatar asked Oct 18 '22 10:10

user3064141


1 Answers

You can disable the built-in CSRF protection Rails uses by default by adding in your controller (ApplicationController or the one being used) the protect_from_forgery method:

protect_from_forgery with: :null_session

Or also by using the skip_before_action to "skip" the verify_authenticity_token implementation.

like image 163
Sebastian Palma Avatar answered Oct 21 '22 09:10

Sebastian Palma