0

在具有通过 Auth0 授权的 next-auth 库的 NextJS 应用程序上,我在授权流程中遇到错误:

[next-auth][error][oauth_get_access_token_error] [
  {
    statusCode: 401,
    data: '{"error":"access_denied","error_description":"Unauthorized"}'
  },
  undefined,
  undefined
] 
https://next-auth.js.org/errors#oauth_get_access_token_error
[next-auth][error][oauth_get_access_token_error] [
  {
    statusCode: 401,
    data: '{"error":"access_denied","error_description":"Unauthorized"}'
  },
  undefined,
  'auth0',
  'HRLMyC9s88eIttwR'
] 
https://next-auth.js.org/errors#oauth_get_access_token_error
[next-auth][error][callback_oauth_error] {
  statusCode: 401,
  data: '{"error":"access_denied","error_description":"Unauthorized"}'
} 
https://next-auth.js.org/errors#callback_oauth_error

没有任何引用的错误有任何细节。

auth0 中的应用程序设置实际上只是Allowed Callback URLs设置http://localhost:3000/api/auth/callback/auth0为 auth0 登录抱怨它的基础。

文件中的 next-auth 配置./api/auth/...[nextauth]如下:

...
    [
      NextAuthProviders.Auth0({
        clientId: process.env.NEXTAUTH_AUTH0_CLIENT_ID,
        clientSecret: process.env.NEXTAUTH_AUTH0_CLIENT_SECRET,
        domain: process.env.NEXTAUTH_AUTH0_DOMAIN,
      })
   ],
   debug: true,
...

什么可能是错误配置?是否有可能通过本地主机上的 next-auth 提供程序运行 auth0?

4

1 回答 1

0

您是否尝试将 Next-auth 配置文件名从...[nextauth]更改为[...nextauth],它应该是./api/auth/[...nextauth],只是跳跃 这是问题所在。

如果没有,正如我在评论中提到的那样:

我已经尝试了这一点,没有使用 next-auth-example进行任何自定义配置,也没有设置自定义服务器来使用 https 运行我的下一个应用程序并且没有本地 SSL 配置,但它仍然适用于 Auth0。

但我一开始有问题,试过了:

  • 在 Windows 中启用 TLS 1.3 支持
  • 在 Chrome 上禁用 QUIC 协议
  • 清除了我的网络历史记录/缓存

然后它开始工作。

于 2021-01-18T10:48:01.413 回答