在https://code.google.com/apis/console网站上,我已经注册了我的应用程序,设置生成的客户端ID:和客户端秘密到我的应用程序,并尝试登录谷歌。 不幸的是,我收到了错误信息:

Error: redirect_uri_mismatch
The redirect URI in the request: http://127.0.0.1:3000/auth/google_oauth2/callback did not match a registered redirect URI

scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
response_type=code
redirect_uri=http://127.0.0.1:3000/auth/google_oauth2/callback
access_type=offline
approval_prompt=force
client_id=generated_id

这条信息是什么意思,我该如何修复它? 我使用宝石omniauth-google-oauth2。


当前回答

我也得到这个错误error -400: redirect_uri_mismatch

这不是一个服务器或客户端错误,但你只需要检查你没有在结尾添加/(正斜杠)就可以了

重定向URL列表❌:

https://developers.google.com/oauthplayground/

这样做只✅:

https://developers.google.com/oauthplayground

其他回答

I had this problem using Meteor and Ngrok, while trying to login with Google. I put the Ngrok URL in the Google Developer Console as redirect URLs, and went to the Ngrok URL page. The thing was that I didn't use Meteor's ROOT_URL when executing the app, so any redirect would go to localhost:3000 insted of the Ngrok URL. Just fixed it by adding the Ngrok URL as ROOT_URL on Meteor's configuration or by exporting it before executing the app on the terminal like: export ROOT_URL=https://my_ngrok_url

就我而言,我补充道

https://websitename.com/sociallogin/social/callback/?hauth.done=Google

在授权重定向uri部分,它为我工作

它已经得到了彻底的回答,但最近(比如,一个月前)谷歌停止接受我的URI,它将无法工作。事实上,我知道它以前做过,因为有一个用户注册了它。

无论如何,问题是常规400:redirect_uri_mismatch,但唯一的区别是,它是从https://更改为http://,和谷歌将不允许您注册http://重定向URI,因为它们是生产发布状态(而不是localhost)。

问题是在我的回调(我使用护照认证),我只做了

callbackURL: "/register/google/redirect"

读文档,他们用的是完整的URL,所以我改成了

callbackURL: "https://" + process.env.MY_URL+ "/register/google/redirect"

将https localhost添加到我接受的URI中,这样我就可以在本地进行测试,它又开始工作了。

TL;DR使用完整的URL,这样你就知道你要重定向到哪里

在我的情况下,我必须检查客户端ID类型的web应用程序/已安装的应用程序。

已安装的应用程序:http://localhost[重定向uri] 在这种情况下,localhost就可以工作了

web应用程序:您需要有效的域名[重定向uri:]

在我的例子中,重置secret ('reset secret'-按钮)就成功了。