-
-
Save shafi-shaikat/d66f18f1151765d7c86ef23da2d03acb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Admin::Api::BaseController < Admin::BaseController | |
after_filter :set_csrf_cookie | |
# For client side js applications needing to qualify for Rails CSRF protection | |
# Normally rails will return its csrf token in the body of the request for html rendering | |
# | |
# In the case of client side apps, we return the token in a cookie | |
# See: https://technpol.wordpress.com/2014/04/17/rails4-angularjs-csrf-and-devise/ | |
def set_csrf_cookie | |
cookies['X-CSRF-TOKEN'] = form_authenticity_token if protect_against_forgery? | |
end | |
private | |
# Allow client side apps to set CSRF tokens in headers | |
def verified_request? | |
super || form_authenticity_token == request.headers['X-CSRF-TOKEN'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment