0

使用stormpath.groupsRequired 中间件调用,

router.get('/',stormpath.loginRequired,stormpath.groupsRequired(['org1-admin']), function (req, res) { res.render('index', {}); });

我无法硬编码“org1-admin”角色,我有什么选择?如果我将它放入 session ,则该 session 不可用于中间件。有什么想法吗?

用户角色 'org1-admin' 将在应用程序启动时根据初始启动请求 url 中传递的 org1 参数和从配置条目中读取的 'admin' 角色来识别。

初始启动后,该角色应可供后续路由授权。感谢您的反馈!

4

1 回答 1

2

如果要检查的组是基于每个请求确定的,则您需要修改流程以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', {});
  });
});

我希望这有帮助!这是一个很好的用例,我想在这个库中添加一些东西,使它更容易做到这一点。

于 2016-07-21T17:26:31.503 回答