使用stormpath.groupsRequired中间件调用,
router.get('/',stormpath.loginRequired,stormpath.groupsRequired('org1-admin'),function (req,res) { res.render('index',{});});
我不能硬编码‘org1-admin’角色,我有什么选择?如果我把它放到一个会话中,这个会话对于中间件是不可用的。有什么想法吗?
当基于初始启动请求url中传递的org1参数和从配置项读取的‘admin’角色启动应用程序时,将识别用户角色‘org1-admin’。
初始启动后,此角色应可用于后续路由进行授权。感谢您的反馈!
发布于 2016-07-22 01:26:32
如果要检查的组是在每个请求的基础上确定的,则需要修改流程以使用更像函数的groupsRequired中间件:
app.get('/', stormpath.loginRequired, function (req, res) {
var group = 'foo'; // grab the group from your request context
stormpath.groupsRequired([group])(req,res,function(){
// If we got here, the user is in the group. Otherwise the groupsRequired middleware would have ended the response with 403
res.render('index', {});
});
});我希望这能帮到你!这是一个很好的用例,我想在这个库中添加一些东西,使其更容易实现。
https://stackoverflow.com/questions/38490495
复制相似问题