Skip to content

Instantly share code, notes, and snippets.

@Lazhari
Created July 29, 2015 05:40
Show Gist options
  • Save Lazhari/e33b979845159d0a3961 to your computer and use it in GitHub Desktop.
Save Lazhari/e33b979845159d0a3961 to your computer and use it in GitHub Desktop.
Protection CSRF with express and AngularJs
app.factory('authInterceptor', function ($cookies) {
return {
// Add authorization token to headers
request: function (config) {
config.headers = config.headers || {};
config.headers.post['x-csrf-token'] =$cookies['XSRF-TOKEN'];
return config;
}
};
});
var csrf = require('csurf');
app.use(csrf());
app.use(function(req, res, next) {
res.cookie('XSRF-TOKEN', req.csrfToken());
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment