oauth-2.0 调试“检查.缺少状态参数”错误AUTH0

roqulrg3  于 2022-10-31  发布在  其他
关注(0)|答案(2)|浏览(206)

我刚刚将新的NextJs blog应用程序https://blog.devdeveloper.ca/部署到Vercal,但我在使用auth0时遇到了问题。当单击屏幕右上角的登录按钮时,用户将被重定向到auth0以完成身份验证流程。
在验证后重定向回我的应用程序时,我收到一个错误(缺少checks.state参数),而且我似乎找不到发生错误的位置。
the error
我偶然发现了这个article,它描述了google chrome在2020年对sameSite属性所做的一个更新,看起来可能与此有关,因为在我的控制台中我得到了以下警告。
sameSite attribute errors
我想知道是否有一些配置选项,我可能是在我的登录处理程序失踪。

import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';

export default handleAuth({
    async login(req, res) {
        try {
            await handleLogin(req, res, {
                authorizationParams: {
                    audience: `http://localhost:5000/`, // or AUTH0_AUDIENCE
                    // Add the `offline_access` scope to also get a Refresh Token
                    scope: 'openid profile email create:category delete:category update:category create:post update:post delete:post create:comment delete:comment', // or AUTH0_SCOPE
                    response_type: "code"
                },

            });

        } catch (error) {
            res.status(error.status || 400).end(error.message);
        }
    }
});

也许我忽略了一些显而易见的事情。

qv7cva1a

qv7cva1a1#

经过更多的调试后,我发现我的重定向URL是不正确的。我去了Vercal,把那个环境变量改为正确的,它成功了!很惊讶,简单的错误竟然会引起一堆头痛。

56lgkhnf

56lgkhnf2#

我也有同样的问题。
对我来说,这个错误只是偶尔发生。我无法找到解决方案,但我找到了一个变通办法。
如前所述,这个错误确实是随机发生的,所以我只是为redirect回调添加了一个自定义处理程序,当这个错误发生时,它会将用户重定向到/
下面是我的pages/api/auth/[...auth0].js文件:

import auth0 from 'src/util/auth0'

export default auth0.handleAuth({
  // other stuff here...
  async callback(req, res) {
    try {
      await auth0.handleCallback(req, res)
    } catch (error) {
      res.redirect('/')
    }
  }
})

相关问题