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

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

我正在开发一个 NextJS 应用程序,使用 next-auth 并使用 Google Oauth 2 作为其身份验证提供程序。生产版本正在 Heroku 上运行。当尝试登录我的生产版本时,Google OAuth 给了我

"Error 400: redirect_uri_mismatch"
。通常,这很容易修复,除非确切的 uri 已在 Cloud Console 中注册。

See my cloud console config

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

1148527169151061未解决此问题。

问题错误:

Error 400: redirect_uri_mismatch

You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy.

If you're the app developer, register the redirect URI in the Google Cloud Console.

Request Details
If you’re the app developer, make sure that these request details comply with Google policies.
redirect_uri: https://middcourses2.herokuapp.com/api/auth/callback/google

Image of error page

And here is a link to the list of authorized domains in GCP.

heroku google-cloud-platform oauth-2.0 google-oauth next-auth
4个回答
6
投票

对我来说,clientID 不是问题,但这是由于 尾部斜杠 ( / )

redirect_uri 必须与开发者控制台上的完全匹配

在 Google Cloud 控制台中,当我的代码在进行 oAuth 调用时发送

http://localhost:8080
时,列表中的重定向 URI 下有
http://localhost:8080/


3
投票

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


1
投票

我遇到了同样的问题,但如果您使用 next-auth 进行身份验证,您应该在授权重定向 URI 中添加

http://localhost:3000/api/auth/callback/google
,请参阅
https://next-auth.js.org/getting-started/rest-api#get-apiauthcallbackprovider
了解更多信息。


1
投票

我也有同样的错误, 就我而言

NEXTAUTH_URL= 'http://localhost:3000' //my origin url

在 .env 中是

NEXTAUTH_URL= 'http://localhost:300'  //my origin url

它是 300 而不是 3000,所以请确保 URL 与来源相同

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