Google OAuth 无法在 Heroku 上运行 - “错误 400:redirect_uri_mismatch

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

我正在使用 NextAuth 和 Google OAuth 提供商在 Next.js 中构建一个应用程序。

我目前已经部署了该应用程序:

  • 在 Vercel 上进行开发
  • 以及 Heroku 上的生产应用程序

为了能够使用 Google OAuth 连接到应用程序,我进入 Google 云控制台并执行了以下操作:

  1. 在 OAuth 同意屏幕设置中,我将 app_name.vercel.app 和 app_name.herokuapp.com 添加到授权域。

  2. 此外,我进入凭据设置,创建了一个 OAuth 2.0 客户端 ID。

对于 vercel 部署,它工作正常。我可以连接并被重定向到该应用程序。但是,对于 heroku 部署,我收到以下错误:

You can’t sign in because this app sent an invalid request. You can try again later, or contact the developer about this issue. Learn more about this error
If you are a developer of this app, see error details.
Error 400: redirect_uri_mismatch

当我点击“错误详细信息”时,我得到以下解释:

Error 400: redirect_uri_mismatch
You cannot log in to the app because it does not comply with Google's OAuth 2.0 policy.
If you are the app developer, register the redirect URI in the Google Cloud Console.
Request details: redirect_uri=http://localhost:3000/api/auth/callback/google

为什么谈论 localhost:3000?有谁知道发生了什么事以及如何解决?

错误 400:redirect_uri_mismatch 错误 400:redirect_uri_mismatch

注意:在 NextAuth 的 OAuth Google 提供程序中,我尝试添加

redirect_uri: "https://www.app_name.herokuapp.com/api/auth/callback/google",

有了这个,我没有得到

Error 400: redirect_uri_mismatch
并且我可以与 Google 连接,但然后我重定向到 http://localhost:3000 所以我没有登录我的应用程序。

heroku deployment google-oauth next-auth redirect-uri-mismatch
1个回答
0
投票

检查图像中的请求详细信息,它会准确告诉您要添加的重定向 URI。

需要完全匹配

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