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


当前回答

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,并尝试这种方法,它将工作。

其他回答

我在谷歌登录时也遇到了同样的问题。

我已经在谷歌开发人员控制台的谷歌凭据面板中正确输入了我的回调 这是我的重定向网址:

https://www.example.com/signin-google

https://www.example.com/signin-google/

https://www.example.com/oauth2callback

https://www.example.com/oauth2callback/

一切似乎都很好,对吧?但它仍然没有工作,直到我添加了一个更神奇的Url,我添加了sign -google Url(这是默认的谷歌回调)没有www和问题解决。

考虑到这一点(取决于你的域名),你可能需要或不需要同时添加www url

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

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

重要补充:我发现在跨客户端服务器认证流程中,当你从Web SDK接收到serverAuthCode时,你应该使用“postmessage”,当你从Android或iOS SDK接收到serverAuthCode时,将redirect_uri设置为空。

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'

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

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,并尝试这种方法,它将工作。