在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。


当前回答

Let me complete @Bazyl's answer: in the message I received, they mentioned the URI "http://localhost:8080/" (which of course, seems an internal google configuration). I changed the authorized URI for that one, "http://localhost:8080/" , and the message didn't appear anymore... And the video got uploaded... The APIS documentation is VERY lame... Every time I have something working with google apis, I simply feel "lucky", but there's a lack of good documentation about it.... :( Yes, I got it working, but I don't yet understand neither why it failed, nor why it worked... There was only ONE place to confirm the URI in the web, and it got copied in the client_secrets.json... I don't get if there's a THIRD place where one should write the same URI... I find nor only the documentation but also the GUI design of Google's api quite lame...

其他回答

就我而言,我补充道

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

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

确保你输入的是URL而不是域名。 所以不要: domain.com 应该是这样 domain.com/somePathWhereYouHadleYourRedirect

当你在https://code.google.com/apis/console注册你的应用程序 创建一个客户端ID,你就有机会指定一个或多个重定向 uri。你的认证URI上的redirect_uri参数的值必须 完全匹配其中一个。

我有同样的问题,在我的本地机器上的端口3000的Reactjs应用程序中授权。 我已经加了lvh。me和http://lvh.me:3000分别为授权来源和授权重定向URL,如下图所示。

注意:您可以为已验证的域添加多个站点。I-e用于本地机器、登台或其他环境

这个问题的主要原因只会来自chrome和chrome处理WWW和非WWW不同取决于你如何在浏览器中输入你的URL,它从谷歌搜索并直接显示结果,所以发送的重定向URL在不同的情况下是不同的

添加所有可能的组合,你可以找到确切的url从fiddler, 400错误弹出不会给你确切的http和www信息