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


当前回答

如果你使用谷歌+ 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(返回响应的地方)必须在api控制台中注册,错误指示您没有这样做,或者没有正确地这样做。

转到项目的控制台,在API Access下查看。您应该在那里看到您的客户端ID和客户端秘密,以及一个重定向uri列表。如果您想要的URI没有列出,单击编辑设置并将URI添加到列表中。

编辑:(来自下面评价很高的评论)请注意,更新谷歌api控制台和当前的更改可能需要一些时间。通常只有几分钟,但有时似乎更长。

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

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

我的观点是: 如果使用Google_Client库,不要忘记在更新重定向URI之后更新服务器上的JSON文件。