1.3.0 • Published 6 years ago

@i2/cake-auth-middleware v1.3.0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
6 years ago

cake-auth-middleware

Express middleware to use https://cakephp.org/ authentication

This package read session data from cake_sessions table using key read from a cookie of the request. If it find an existing session, the module decode it using groan to decode PHP session informations.

Usage

how to load the middleware:

const cakeAuthMiddleware = require('cake-auth-middleware');
const asyncExpress = require('async-express');
const express = require('express');

const app = express();
asyncExpress(app);

const cookieName = 'PHPSESSID';
const knex; // construct a knex connection
app.useAsync(cakeAuthMiddleware(cookieName, knex))

...

API

export default (cookieName: string, knex: object): Function(req, res, next)

return the middleware function to install in expressjs app.

  • cookieName: string - name of the client cookie containing cake session id.
  • knex: object - an already setted-up knex connection.
export const check (groupNames: Array<string>): Function(req, res, next)

return a MW that calls next middleware only if logged cake user belongs to any of given groups.

  • groupNames: Array - name of groups to check.

Example

const {check} = require('cake-auth-middleware');

const admins = check(['Admins', 'Superusers']);

// ... set up express app and routes

app.get('/admin-dashboard', admins, (req, res) => {
	res.send('visible to admins only');
})

Install

With npm installed, run

$ npm install cake-auth-middleware

See Also

License

UNLICENSED. Copyright 2016 i2 S.r.l.

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago