繁体   English   中英

Auth0 - 不足 scope

[英]Auth0 - Insufficient scope

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

我一直在寻找一段时间,发现了一堆类似的问题,但无法找到解决方案。

本质上,在我的节点应用程序中,我必须按如下方式保护一条路线:

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

但是,在添加中间件以保护我的路由时,我总是收到Insufficient scope错误:

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

请问你能帮帮我吗?

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

用这个:

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

代替

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

您可以尝试const checkScopes = jwtAuthz(['read:flights'], { customUserKey: "auth" });

默认情况下,根据 req.user 检查权限。 但是,我注意到在最新版本中, req.user 是未定义的。 相反,令牌位于 req.auth

你拯救了我的理智和我的生意。 神速你。

只是重申(举例)......

app.get('/test', jwtCheck, jwtAuthz(['read:generatedLeads'], { customScopeKey: "permissions", customUserKey: "auth" }),  (req, res) => {
    infoLogger.info(FILE_NAME, METHOD, "Health Check is passing...")
    res.status(200).send({health: "Token Accepted"})
})

添加 customUserKey: "auth" 作为 jwtAuthz 配置的一部分解决了我的“范围不足”错误问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM