Last active
August 29, 2015 14:01
-
-
Save abelmartin/802ed23e818850d242fd to your computer and use it in GitHub Desktop.
AngularJS CSRF token stuff
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 ApplicationController < ActionController::Base | |
#Deailing with AngularJS CRSF issues | |
#... | |
protect_from_forgery with: :exception | |
after_action :set_ng_csrf_token | |
#... | |
protected | |
# Dealing with CSRF token issues. | |
def set_ng_csrf_token | |
cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery? | |
end | |
def verified_request? | |
super || form_authenticity_token == request.headers['X-XSRF-TOKEN'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment