Skip to content

Instantly share code, notes, and snippets.

@thelonecabbage
Last active December 22, 2015 14:18
Show Gist options
  • Save thelonecabbage/6484328 to your computer and use it in GitHub Desktop.
Save thelonecabbage/6484328 to your computer and use it in GitHub Desktop.
CSRF Tokens with AngularJS
// note the $httpProvider
// must be called AFTER login (ie ajax login)
function($httpProvider, $http) {
$httpProvider.defaults.headers.post['X-CSRFToken'] = (document.cookie.match(/csrftoken=([0-9a-zA-Z]*)/) || ['']).pop();
};
//alternately, dont' forget to install angular-cookies.js
function($http, $cookies){
$http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment