I am going to create a new AngularJS interface for the Drupal 7 site. This uses the Services module with session-based authentication across two domains using CORS. I can authenticate with Drupal, get the user object and session data, and then get the CSRF token from the services module. I'm having trouble setting all this up in the header so that subsequent requests are authenticated. I understand the general concept, but new to both AngularJS and preventing CSRF attacks.
From what I compiled by reading about this setting with AngularJS and RubyOnRails, there may be inconsistencies between the platforms regarding what the token is designated and how it is processed. A number of suggestions are also presented on how to set this token in the header. However, I had trouble finding a convincing example of how to get these platforms to speak the same language.
The only thing I do with my $ httpProvider in app.js:
delete $httpProvider.defaults.headers.common['X-Requested-With'];
Controller controller login .js:
.controller('LoginCtrl', ['$scope', '$http', '$cookies', 'SessionService', function($scope, $http, $cookies, SessionService) { $scope.login = function(user) { //set login url and variables var url = 'http://mywebsite.com/service/default/user/login.json'; var postDataString = 'name=' + encodeURIComponent(user.username) + '&pass=' + encodeURIComponent(user.password); $http({ method: 'POST', url: url, data : postDataString, headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function (data, status, headers, config) { var sessId = data.sessid; var sessName = data.session_name; $cookies[sessName] = sessId; var xsrfUrl = 'http://mywebsite.com/services/session/token'; $http({ method: 'GET', url: xsrfUrl }).success(function (data, status, headers, config) { $cookies["XSRF-TOKEN"] = data; SessionService.setUserAuthenticated(true); }).error(function (data, status, headers, config) { console.log('error loading xsrf/csrf'); }); }).error(function (data, status, headers, config) { if(data) { console.log(data); var msgText = data.join("\n"); alert(msgText); } else { alert('Unable to login'); } }); };