瀏覽代碼

Make csrf work for angular

Lily Carpenter 10 年之前
父節點
當前提交
51773da5bd
共有 1 個文件被更改,包括 11 次插入0 次删除
  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