Last active
December 22, 2015 14:18
-
-
Save thelonecabbage/6484328 to your computer and use it in GitHub Desktop.
CSRF Tokens with AngularJS
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
// 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