Parcourir la Source

Make csrf work for angular

Lily Carpenter il y a 10 ans
Parent
commit
51773da5bd
1 fichiers modifiés avec 11 ajouts et 0 suppressions
  1. 11 0
      twilio/app/controllers/application_controller.rb

+ 11 - 0
twilio/app/controllers/application_controller.rb

2
   # Prevent CSRF attacks by raising an exception.
2
   # Prevent CSRF attacks by raising an exception.
3
   # For APIs, you may want to use :null_session instead.
3
   # For APIs, you may want to use :null_session instead.
4
   protect_from_forgery with: :exception
4
   protect_from_forgery with: :exception
5
+
6
+  after_filter :set_csrf_cookie_for_ng
7
+  def set_csrf_cookie_for_ng
8
+    cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
9
+  end
10
+
11
+  protected
12
+
13
+  def verified_request?
14
+    super || form_authenticity_token == request.headers['X-XSRF-TOKEN']
15
+  end
5
 end
16
 end