使用自定义提供程序进行身份验证时,NextAuth 给出错误 OAUTH_CALLBACK_ERROR invalid_client

问题描述 投票:0回答:1

我尝试使用 NextAuth 通过自定义 oauth2 提供程序进行身份验证 (Whoop),但是在 whoop 服务器上完成登录并且我被重定向回我的应用程序后,NextAuth 会抛出以下错误:

[next-auth][error][OAUTH_CALLBACK_ERROR] 
https://next-auth.js.org/errors#oauth_callback_error invalid_client (Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method)) {
  error: OPError: invalid_client (Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method))
      at processResponse (webpack-internal:///(sc_server)/./node_modules/openid-client/lib/helpers/process_response.js:35:19)
      at Client.grant (webpack-internal:///(sc_server)/./node_modules/openid-client/lib/client.js:1191:28)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Client.oauthCallback (webpack-internal:///(sc_server)/./node_modules/openid-client/lib/client.js:520:30)
      at async oAuthCallback (webpack-internal:///(sc_server)/./node_modules/next-auth/core/lib/oauth/callback.js:120:22)
      at async Object.callback (webpack-internal:///(sc_server)/./node_modules/next-auth/core/routes/callback.js:18:83)
      at async AuthHandler (webpack-internal:///(sc_server)/./node_modules/next-auth/core/index.js:202:38)
      at async NextAuthRouteHandler (webpack-internal:///(sc_server)/./node_modules/next-auth/next/index.js:49:30)
      at async NextAuth._args$ (webpack-internal:///(sc_server)/./node_modules/next-auth/next/index.js:83:24)
      at async eval (webpack-internal:///(sc_server)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:242:37) {
    name: 'OAuthCallbackError',
    code: undefined
  },
  providerId: 'whoop',
  message: 'invalid_client (Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method))'
}

我的配置如下:

// /api/auth/[...nextauth]/route.ts
import NextAuth, { AuthOptions } from "next-auth";

export const authOptions: AuthOptions = {
  //   debug: true,
  providers: [
    {
      id: "whoop",
      name: "Whoop",
      type: "oauth",
      token: "https://api.prod.whoop.com/oauth/oauth2/token",
      authorization: {
        url: "https://api.prod.whoop.com/oauth/oauth2/auth",
        params: {
          scope: "read:profile read:workout read:recovery",
        },
      },

      clientId: process.env.WHOOP_CLIENT_ID,
      clientSecret: process.env.WHOOP_CLIENT_SECRET,
      userinfo: "https://api.prod.whoop.com/developer/v1/user/profile/basic",
      profile(profile) {
        return {
          id: profile.user_id,
          first_name: profile.first_name,
          last_name: profile.last_name,
          email: profile.email,
        };
      },
    }
  ]
};

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };

我相当确定这不是配置中存在的任何变量的问题。 clientID、秘密、回调 url 和范围都可以很好地与 whoop 配合使用。此外,

profile
函数似乎不会引起问题 - 我尝试在不访问
profile
参数的情况下手动设置值,并且错误仍然存在。

任何有关调试的帮助将不胜感激!

authentication next.js oauth next-auth app-router
1个回答
0
投票

您能找到解决方案吗?

© www.soinside.com 2019 - 2024. All rights reserved.