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


当前回答

我需要在api和服务下创建一个新的客户端ID ->凭据->创建凭据-> OAuth ->其他

然后下载并使用client_secret。Json和我的命令行程序上传到我的YouTube帐户。我试图使用Web应用程序OAuth客户端ID,这给了我浏览器中的重定向URI错误。

其他回答

我在控制台中有两个请求uri, http://xxxxx/client/api/spreadsheet/authredirect和http://localhost。

我尝试了这个问题的所有回答,并确认没有一个是我的问题。

我从控制台删除了localhost,更新了client_secret。Json在我的项目中,不匹配错误消失了。

如果你使用谷歌+ javascript按钮,那么你必须使用postmessage而不是实际的URI。我花了几乎一整天的时间才弄清楚,因为谷歌的文档出于某种原因没有清楚地说明它。

The trick is to input the right redirect url at the point of creating the ID. I found that updating the redirect url once the ID has been created via an 'Edit' just doesn't get the job done. What also worked for me is duplicating the entire 'vendor' folder and copying it to the same location where the 'oauth' file is (just until you successfully generate the token and then you can delete the duplicate 'vendor' folder). This is because trying to point to the vendor folder via '../vendor/autoload' didn't work for me.

因此,删除您现有的麻烦客户端OAuth ID,并尝试这种方法,它将工作。

它已经得到了彻底的回答,但最近(比如,一个月前)谷歌停止接受我的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,这样你就知道你要重定向到哪里

不要忘记在域名和ip后面加上路径。就我而言,我忘记了:

/ oauth2callback