Created
July 29, 2015 05:40
-
-
Save Lazhari/e33b979845159d0a3961 to your computer and use it in GitHub Desktop.
Protection CSRF with express and AngularJs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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