express-drupal7-session-middleware

    2.0.0-alpha.9 • Public • Published

    Express middleware to retrieve a user session from a drupal 7 cookie

    Express middleware for Drupal 7 authentication

    CircleCI Greenkeeper badge

    Install

    npm i express-drupal7-session-middleware

    You need to use knex query builder to use this package.

    npm i cookie-parser knex

    See knex documentation on how to create a new instance.

    Usage

    In your server definition

      const { drupalExpressMiddleware } = require('express-drupal7-session-middleware');
    
      app.httpServer = http.createServer(app);
      // ...
      app.use(cookieParser());
      app.use(drupalExpressMiddleware('local.my-website.com', knex));

    then in your routes

      const { drupalUserAccess, drupalCSRFToken } = require('express-drupal7-session-middleware');
    
      const myRoute = async (req, res) => {
        const access = await drupalUserAccess(knex, 'access api myRoute', req.userId);
        if (!access) {
          return res.status(403).send();
        }
    
        // Bonus if you need it
        console.log(req.cookieSessionText);
        // -- and --
        const drupalHashSalt = 'fwf3qfwgrbq34h34qeg134g3434g5340f-0f';
        const csrfToken = await drupalCSRFToken(knex, req.sessionId, drupalHashSalt, 'services'));
        res.json({ csrfToken });
      }

    Keywords

    none

    Install

    npm i express-drupal7-session-middleware

    DownloadsWeekly Downloads

    15

    Version

    2.0.0-alpha.9

    License

    MIT

    Unpacked Size

    35.3 kB

    Total Files

    15

    Last publish

    Collaborators

    • rawpixel