blob: 5f87de58ba46a481434be288d1fd58e3896981d5 [file] [log] [blame]
Matteo Scandolo817386b2015-11-04 16:07:09 +01001(function() {
Matteo Scandolo582cc812016-04-13 17:23:28 -07002 'use strict';
Matteo Scandolo817386b2015-11-04 16:07:09 +01003
Matteo Scandolo582cc812016-04-13 17:23:28 -07004 /**
5 * @ngdoc service
6 * @name xos.helpers.SetCSRFToken
7 * @description This factory is automatically loaded trough xos.helpers and will add an $http interceptor that will the CSRF-Token to your request headers
8 **/
Matteo Scandolo817386b2015-11-04 16:07:09 +01009
Matteo Scandolo582cc812016-04-13 17:23:28 -070010 angular
11 .module('xos.helpers')
12 .factory('SetCSRFToken', setCSRFToken);
13
14 function setCSRFToken($cookies) {
15 return {
16 request: function(request){
17 if(request.method !== 'GET'){
18 request.headers['X-CSRFToken'] = $cookies.get('xoscsrftoken');
Matteo Scandolo817386b2015-11-04 16:07:09 +010019 }
Matteo Scandolo582cc812016-04-13 17:23:28 -070020 return request;
21 }
22 };
23 }
Matteo Scandolo9323b1b2015-11-25 12:08:41 -080024})();