Matteo Scandolo | a5d03d5 | 2016-07-21 11:35:46 -0700 | [diff] [blame] | 1 | (function() { |
| 2 | 'use strict'; |
| 3 | |
| 4 | /** |
| 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 | **/ |
| 9 | |
| 10 | 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'); |
| 19 | } |
| 20 | return request; |
| 21 | } |
| 22 | }; |
| 23 | } |
| 24 | })(); |