Skip to content

Instantly share code, notes, and snippets.

@ZellSnippets
Created July 7, 2014 08:50
Show Gist options
  • Save ZellSnippets/951f63b8e81422c478a6 to your computer and use it in GitHub Desktop.
Save ZellSnippets/951f63b8e81422c478a6 to your computer and use it in GitHub Desktop.
Angular: CSRF Token Cookies for Drupal Services
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