Created
July 7, 2014 08:50
-
-
Save ZellSnippets/951f63b8e81422c478a6 to your computer and use it in GitHub Desktop.
Angular: CSRF Token Cookies for Drupal Services
This file contains 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
config(['$httpProvider', | |
function($httpProvider) { | |
// Change header XSRF Name to match Drupal's required token | |
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-TOKEN'; | |
} | |
]). | |
run(['$http', '$cookies', | |
function($http, $cookies) { | |
delete $cookies['XSRF-TOKEN']; | |
$http.get('/services/session/token').success(function(token) { | |
$cookies['XSRF-TOKEN'] = token; | |
console.log($cookies['XSRF-TOKEN']); | |
}) | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment