Explorar el Código

Make csrf work for angular

Lily Carpenter hace 10 años
padre
commit
51773da5bd
Se han modificado 1 ficheros con 11 adiciones y 0 borrados
  1. 11 0
      twilio/app/controllers/application_controller.rb

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

@@ -2,4 +2,15 @@ class ApplicationController < ActionController::Base
2 2
   # Prevent CSRF attacks by raising an exception.
3 3
   # For APIs, you may want to use :null_session instead.
4 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 16
 end