Auth0-范围不足

时间:2019-11-29 22:55:57

标签: node.js authentication auth0

我在Node.js应用程序中使用Auth0,并且在尝试保护应用程序中的任何路由时遇到作用域不足错误。

我已经搜索了一段时间,但发现了一堆类似的问题,但是却找不到解决方法。

本质上,在我的节点应用中,我必须按以下方式保护路由:

const checkScopes = jwtAuthz(['read:flights']);

但是,添加中间件来保护我的路线时,我总是会收到范围不足错误:

app.get('/api/permission', checkJwt, checkScopes, (req, res) => {
  res.send({
    msg: 'Your access token AND PERMISSION was successfully validated!'
  });
});

能帮我吗?

1 个答案:

答案 0 :(得分:1)

您应该包括另一个名为“ customScopeKey”的参数,这样auth0将使用权限而不是范围来验证用户凭据。

使用此:

const checkScopes = jwtAuthz(['read:flights'], { customScopeKey: "permissions" });

代替

const checkScopes = jwtAuthz(['read:flights']);