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


当前回答

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

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

其他回答

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

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

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

在GO中,这解决了问题:

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

Rails用户(来自omniauth-google-oauth2文档):

修复redirect_uri在Rails中的协议不匹配 只需要根据Rails.env在OmniAuth中设置full_host。 #配置/初始化/ omniauth.rb OmniAuth.config。full_host = Rails.env.production?? 'https://domain.com': 'http://localhost:3000'

记住:不要包括后面的"/"

更新—>适用于Android应用程序

只使用:

http://localhost/oauth2callback

如果你处理自己的逻辑没有重定向链接的web应用程序