How to use the koa-csrf.middleware function in koa-csrf

To help you get started, we’ve selected a few koa-csrf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github easynode / easynode / src / easynode / framework / server / http / KOAHttpServer.js View on Github external
// access log
        if (me.writeAccessLog()) {
          app.use(me._createAccessLogger());
        }

                                // session support
        app.use(session({
          store: me._getSessionStore()
        }));

                                // csrf support
        if (me._enableCSRF === true) {
          var csrf = require('koa-csrf');
          csrf(app);
          app.use(csrf.middleware);
        }

                                // parse url query string and body before any middleware defined by user is running
        qs(app, 'first');                       // /foo?a=b&a=c         this.query.a = 'b' , not a = ['b', 'c']

                                // support multipart-form-data
        me._createMultipartMiddleware(app);

                                // default middlewares
        me._createDefaultMiddlewares(app);

                                // user defined middlewares
        me._createExtraMiddlewares(app);

                                // inner routes
        me._createDefaultRoutes(app);
github Chiara-yen / startLearningNodejs / ex-55-koa-csrf / app.js View on Github external
var koa = require('koa');
var csrf = require('koa-csrf');
var session = require('koa-session');
var bodyParser = require('koa-bodyparser');
var router = require('koa-router')();

var app = koa();

app.use(bodyParser());

app.keys = ['session secret'];
app.use(session(app));

csrf(app);
app.use(csrf.middleware);

router.get('/form', function *() {
  // pass the csrfToken to the view
  var html =
    '' +
    '' +
    '' +
      '' +
      '<title>Document</title>' +
    '' +
    '' +
      '<form method="POST" action="/process">' +
        '<input value="' + this.csrf + '" name="_csrf" type="hidden">' +
        'Favorite color: <input name="favoriteColor" type="text">' +
        '<button type="submit">Submit</button>' +
      '</form>' +

koa-csrf

CSRF tokens for Koa

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis

Popular koa-csrf functions