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


当前回答

你需要做的是回到开发人员控制台,进入api & Auth >同意屏幕,然后填写。具体来说,就是产品名称。

其他回答

对于我的web应用程序,我纠正了我的错误

instead of : http://localhost:11472/authorize/
type :      http://localhost/authorize/

我也得到这个错误error -400: redirect_uri_mismatch

这不是一个服务器或客户端错误,但你只需要检查你没有在结尾添加/(正斜杠)就可以了

重定向URL列表❌:

https://developers.google.com/oauthplayground/

这样做只✅:

https://developers.google.com/oauthplayground

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

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