Next.js 使用Okta身份验证进行下一次身份验证时出错

Next.js 使用Okta身份验证进行下一次身份验证时出错,next.js,okta,next-auth,Next.js,Okta,Next Auth,我在使用next auth和Okta作为提供程序时遇到错误。它会将我重定向回我的应用程序,但我会看到一个页面,上面写着“尝试使用其他帐户登录”,并重定向到“api/auth/signin?error=Callback” 使用next auth的调试器在终端中遇到的错误是: [next-auth][debug][oauth_callback_protection] Comparing received and expected state { state: 'b3ef7bf3d4a5aa8f5

我在使用next auth和Okta作为提供程序时遇到错误。它会将我重定向回我的应用程序,但我会看到一个页面,上面写着“尝试使用其他帐户登录”,并重定向到“api/auth/signin?error=Callback”

使用next auth的调试器在终端中遇到的错误是:

[next-auth][debug][oauth_callback_protection] Comparing received and expected state {
  state: 'b3ef7bf3d4a5aa8f5f81fc95260502b0a206180bd0a831bb27b26d8c21271e33',
  expectedState: 'b3ef7bf3d4a5aa8f5f81fc95260502b0a206180bd0a831bb27b26d8c21271e33'
}

[next-auth][error][oauth_get_access_token_error] 
https://next-auth.js.org/errors#oauth_get_access_token_error {
  statusCode: 401,
  data: '{"errorCode":"invalid_client","errorSummary":"No client credentials found.","errorLink":"invalid_client","errorId":"******************","errorCauses":[]}'
} undefined undefined

[next-auth][error][oauth_get_access_token_error] 
https://next-auth.js.org/errors#oauth_get_access_token_error {
  statusCode: 401,
  data: '{"errorCode":"invalid_client","errorSummary":"No client credentials found.","errorLink":"invalid_client","errorId":"**************","errorCauses":[]}'
} okta ************************

[next-auth][error][oauth_callback_error] 
https://next-auth.js.org/errors#oauth_callback_error {
  statusCode: 401,
  data: '{"errorCode":"invalid_client","errorSummary":"No client credentials found.","errorLink":"invalid_client","errorId":"*******************","errorCauses":[]}'
}
这是我的Okta应用程序设置:

我已经检查了cliendID和客户机密,它们是正确的。有人有什么线索吗? 我知道它可以与okta一起使用,因为我已经让它与另一个应用程序一起使用,但我尝试复制完全相同的设置

在[…nextuth].js中:

      Providers.Okta({
          clientId: process.env.OKTA_CLIENT_ID,
          clientSecret: process.env.OKTA_CLIENT_SECRET,
          domain: process.env.OKTA_DOMAIN,
          accessTokenUrl: `https://${process.env.OKTA_DOMAIN}/oauth2/default/v1/token`,
          authorizationUrl: `https://${process.env.OKTA_DOMAIN}/oauth2/default/v1/authorize/?response_type=code`,
      })

这是下一个auth包中的一个bug。遇到同样的问题,在与同事调试并尝试了一些东西之后,我们找到了下面的补丁,它适合我们

diff--git a/node_modules/next auth/dist/server/lib/oauth/client.js b/node_modules/next auth/dist/server/lib/oauth/client.js
索引b4e48c2..7f68dd7 100644
---a/node_modules/next auth/dist/server/lib/oauth/client.js
+++b/node_modules/next auth/dist/server/lib/oauth/client.js
@@-160,7+160,7@@function\u getOAuth2AccessToken(){
headers.Authorization='Basic'+Buffer.from(provider.clientId+':'+provider.clientSecret.toString('base64');
}
-if((provider.id=='okta'| | provider.id==='identity-server4')&&&!headers.Authorization){
+if((provider.id=='identity-server4')&&!headers.Authorization){
headers.Authorization=“Bearer.concat(代码);
}
问题似乎是将客户端id和机密作为查询参数发送,但也发送授权标头。删除授权标头使idp集成工作正常


同样值得注意的是;

我对谷歌有这个问题,你认为这个解决方案适用于所有提供商还是仅仅适用于okta?