Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/weisjohn/superagent-csrf-middleware

easily handle CSRF tokens with superagent
https://github.com/weisjohn/superagent-csrf-middleware

Last synced: about 1 month ago
JSON representation

easily handle CSRF tokens with superagent

Awesome Lists containing this project

README

        

# superagent-csrf-middleware

easily handle CSRF tokens with superagent

Supports simple CSRF implementations and those which modify the token with each request.

### usage

```javascript

var request = require('superagent');
var csrf = require('superagent-csrf-middleware');
var agent = request(server);

var csrf1 = csrf();
agent.get('/foo')
.use(csrf1)
.end(function() {
agent.post('/bar')
.use(csrf1)
.end(function() {
/* ... */
});
});
```

### options

By default, `superagent-csrf-middleware` looks at the `XSRF-TOKEN` cookie and sets the `X-XSRF-TOKEN` header.

You may optionally define other parameters:

```javascript
var cookie = 'MY-XSRF-COOKIE-NAME';
var header = '_SEASURF';
var csrf = require('superagent-csrf-middleware')(cookie, header);
```

### support

This is known to work with [lusca](https://github.com/krakenjs/lusca)'s CSRF implementation.