Created
August 27, 2014 17:23
-
-
Save sangcu/1777762dc3f54f79599f to your computer and use it in GitHub Desktop.
How to check authentication on incoming request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var _ = require('underscore'); | |
| var authenController = require('../controllers/authentication'); | |
| var config = require('../configs/config'); | |
| var constant = require('../configs/constant'); | |
| module.exports = { | |
| authen:function(req, res, next){ | |
| var domain = req.customdomain; | |
| var token = req.header("token"); | |
| if(!domain || !token){ | |
| res.send(401,{message:req.i18n.t("app.unauthentication")}); | |
| } | |
| authenController.authen(domain,token,req.originalUrl).then(function(session){ | |
| //config.writeLog('authen pass'); | |
| //config.writeLog(session); | |
| req.session=session; | |
| req.accessType={}; | |
| if(!_.isEmpty(session)){ | |
| req.accessType.system = _.indexOf(session.roles, constant.ROLES.SystemAdministration)>=0; | |
| req.accessType.app = _.indexOf(session.roles, constant.ROLES.AppAdministration)>=0; | |
| req.accessType.secretary = _.indexOf(session.roles, constant.ROLES.AppSecretary)>=0; | |
| } | |
| next(); | |
| }).catch(function(err){ | |
| res.send(401,err); | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment