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


当前回答

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

其他回答

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

试着做这些检查:

控制台和应用程序中的Bundle ID。我更喜欢这样设置应用程序的Bundle ID: "org.peredovik.${PRODUCT_NAME:rfc1034identifier}" 检查你是否在信息选项卡添加了URL类型,只需在标识符和URL方案中输入你的Bundle ID,角色设置为编辑器 在控制台cloud.google.com“api & auth”->“同意屏幕”填写关于您的应用程序的表格。“产品名称”是必填字段。

享受:)

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

以下是Error: redirect_uri_mismatch问题发生的原因:

重定向URL字段空白在您的谷歌项目。 重定向URL与您的网站不匹配 重要!它将只与工作域,如example.com, book.com等(不与本地主机或AWS LB URL工作)

建议使用域URL

2015年7月15日-上周在登录时使用这个脚本工作的登录

<script src="https://apis.google.com/js/platform.js" async defer></script>

停止工作并开始导致Error 400 with Error: redirect_uri_mismatch

然后在DETAILS部分:redirect_uri=storagerelay://…

我把它改成:

<script src="https://apis.google.com/js/client:platform.js?onload=startApp"></script>