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


当前回答

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

其他回答

要使它在本地主机上工作,如果使用web服务器,请提供

Authorized JavaScript origins (Client ID for web appication)
e.g. http://localhost:4200

确保检查协议“http://”或“https://”,因为谷歌也检查协议。 最好将两个URL都添加到列表中。

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...

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

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

就我而言,我补充道

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

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