【问题标题】:Hapi - how to access route scope from request objectHapi - 如何从请求对象访问路由范围
【发布时间】:2018-11-16 04:37:57
【问题描述】:

我有一个 Hapi API,使用 JWT 进行身份验证。我的 JWT 的验证功能是

let validate = (decoded, request, callback) => {
  // decoded.permissions is an array of the users's permissions

我的路由定义如下动态范围;

path: "/{portalId}/somedata",
method: "POST",
config: {
  auth: {
    strategy: "jwt",
    scope: ['user-{params.portalId}']
  }

我想将调用限制为只允许用户的权限数组包含“user-1”的项目,但我不知道在我的验证函数中检查什么。

在请求的哪里可以找到当前调用的路由范围限制?

或者,我还能如何构建这个方案来满足我的需要?

【问题讨论】:

    标签: hapijs


    【解决方案1】:

    Welp,我最终以不同的方式解决了它

    我的路线保持不变,但在验证函数中,我根据解码的 userId 构造了一个范围字符串数组,然后将其添加到范围

    userPermissions: string[] = buildUserPermissions(userId);
    // after they pass any checks
    return callback(null, true, {scope: userPermissions, user: user} );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 2021-07-20
      • 2011-01-02
      相关资源
      最近更新 更多