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


当前回答

1.您将看到类似这样的错误

2.然后单击请求详细信息

在此之后,您必须复制该url并将其添加到https://console.cloud.google.com/

访问https://console.cloud.google.com/

点击菜单-> API和服务->凭证

你会看到一个这样的仪表板,点击编辑OAuth客户端 现在在授权Javascript起源和授权重定向url 添加显示错误的url,称为redirect_uri_mismatch,即这里 http://algorithammer.herokuapp.com,所以我在这两个地方都加了 授权Javascript源和授权重定向url 点击保存,等待5分钟,然后尝试再次登录

其他回答

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>

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

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

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

重定向url区分大小写。

在我的例子中,我添加了两个: http://localhost:5023/AuthCallback/IndexAsync http://localhost:5023/authcallback/indexasync

如果你使用这个教程:https://developers.google.com/identity/sign-in/web/server-side-flow,那么你应该使用“postmessage”。

在GO中,这解决了问题:

confg = &oauth2.Config{
        RedirectURL:  "postmessage",
        ClientID:   ...,
        ClientSecret: ...,
        Scopes:      ...,
        Endpoint:     google.Endpoint,
}

试着做这些检查:

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

享受:)