Matteo Scandolo | 889ced3 | 2015-11-04 16:07:09 +0100 | [diff] [blame] | 1 | (function() { |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 2 | 'use strict'; |
Matteo Scandolo | 889ced3 | 2015-11-04 16:07:09 +0100 | [diff] [blame] | 3 | |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 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 | **/ |
Matteo Scandolo | 889ced3 | 2015-11-04 16:07:09 +0100 | [diff] [blame] | 9 | |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 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'); |
Matteo Scandolo | 889ced3 | 2015-11-04 16:07:09 +0100 | [diff] [blame] | 19 | } |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 20 | return request; |
| 21 | } |
| 22 | }; |
| 23 | } |
Matteo Scandolo | d3de390 | 2015-11-25 12:08:41 -0800 | [diff] [blame] | 24 | })(); |