Last active
December 18, 2015 16:09
-
-
Save kieran/5809865 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Api::V1::ApplicationController < ActionController::Base | |
protect_from_forgery | |
before_filter :set_csrf_header | |
private | |
def set_csrf_header | |
response.headers['X-CSRF-Token'] = session[:_csrf_token] ||= SecureRandom.base64(32) | |
end | |
end |
This file contains hidden or 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
$.ajaxSetup | |
xhrFields: | |
withCredentials: true | |
$(document).ajaxSend (event, jqxhr, settings)-> | |
jqxhr.setRequestHeader 'X-CSRF-Token', Embed.get 'csrf-token' | |
$(document).ajaxComplete (event, jqxhr, settings)-> | |
if jqxhr.getResponseHeader('X-CSRF-Token')? | |
Embed.set 'csrf-token', jqxhr.getResponseHeader 'X-CSRF-Token' |
This file contains hidden or 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
module Api | |
module V1 | |
class ListingsController < ApplicationController | |
# ... | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment