0.0.4 • Published 9 years ago

x-auth v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

Installation

$ npm install x-auth

Usage

var express = require('express');
var router  = express.Router();
var XAuth 	= require('x-auth');

var xAuth = new XAuth({
    getUserRole: function(req, res){
    	return "Admin";
    },
    beforeAuthorization: [
			// middleware functions are executed before Authorization function
			function(req, res, next){

				next();
			},
			function(req, res, next){

				next();
			}
    ],
    onFailureAuthorization: function(req, res){
			res.send(401, 'Unauthorized');
  	}
});

// register roles
xAuth.register("User");
xAuth.register("Admin");

// Admin extends User and gets access to everything that User can access.
xAuth.extend('Admin', 'User');

// User can access 'home' endpoint.
// Admin extends User, so Admin also has access to 'home' endpoint.
xAuth.canAccess('User', ['home']);

router.use('/theme', require('./controllers/ThemeController')({xAuth: xAuth}).router);

module.exports = router;

inside: ./controllers/ThemeController

var express = require('express');
var router  = express.Router();

var Controller = function(settings){

	router.get(
		'/',
		// add route endpoint
		settings.xAuth.endpoint('home').concat(
		function(req, res) {
			
			
	}));
	
	return {
		router: router
	};
};

module.exports = Controller;
0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago