Google OAuth 2 错误 400:redirect_uri_mismatch 但重定向 uri 合规且已在 Google Cloud Console 中注册

Nic*_*ter 8 heroku oauth-2.0 google-oauth google-cloud-platform next-auth

我正在开发一个 NextJS 应用程序,使用 next-auth 并使用 Google Oauth 2 作为其身份验证提供程序。生产版本正在 Heroku 上运行。当尝试登录我的生产版本时,Google OAuth 为我提供了"Error 400: redirect_uri_mismatch". 通常,这很容易修复,除非确切的 uri 已在 Cloud Console 中注册。

\n

查看我的云控制台配置

\n

我还尝试添加我的 uri 的许多不同排列,但这没有帮助。

\n

1148527169151061未解决此问题。

\n

问题中的错误:

\n
Error 400: redirect_uri_mismatch\n\nYou can\'t sign in to this app because it doesn\'t comply with Google\'s OAuth 2.0 policy.\n\nIf you\'re the app developer, register the redirect URI in the Google Cloud Console.\n\nRequest Details\nIf you\xe2\x80\x99re the app developer, make sure that these request details comply with Google policies.\nredirect_uri: https://middcourses2.herokuapp.com/api/auth/callback/google\n
Run Code Online (Sandbox Code Playgroud)\n

错误页面的图片

\n

这里是 GCP 中授权域名列表的链接。

\n

Kau*_*nia 6

对我来说, clientID 不是问题,但这是由于尾随斜杠 ( / )造成的。

在开发者控制台上,redirect_uri 必须完全匹配。

在 Google Cloud 控制台中,当我的代码在进行 oAuth 调用时http://localhost:8080发送时,我的重定向 URI 位于列表中。http://localhost:8080/


Nic*_*ter 3

解决了!因此,出于某种原因,在我设置了这些环境变量后,Google 更改了我的客户端 ID 和客户端密钥。一旦我注意到变化并输入新值,它就可以正常工作。