OAuth 2.0 sample error when accessing Google API

荒凉一梦 提交于 2019-12-11 03:30:00

问题


With the open source project google-api-ruby-client, I'm trying to run the OAuth 2.0 sample calendar.rb, which will access Google Calendar API. I've created client ID in Google API console, and fill the client ID and the secret in the ruby script.

However, after I run the ruby script

ruby calendar.rb

and then open http://localhost:4567, the browser return error information from Google to me:

Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:4567/oauth2callback did not match a     registered redirect URI

I checked the information in the Google API console:

Redirect URIs:  https://localhost/oauth2callback
JavaScript origins: https://localhost

What's the problem and how to solve it? Thanks in advance.


回答1:


The redirect URI has to match exactly. You can't omit anything. You've dropped the port number. But mismatching a trailing slash or really anything else will cause this error. It has to be an exact, character-for-character match.

The two values should be:

Redirect URIs: https://localhost:4567/oauth2callback

JavaScript origins: https://localhost:4567




回答2:


I didn't have the port numbers and it worked fine.

However, the Redirect URI was: http://localhost/oauth2callback

I had this example working last night.




回答3:


I faced the same problem. Everything was matching, URL was correct, consent page was filled, but I had to generate a new Client ID three times. It started working just on the third time. I don't know the reason. I didn't change anything in configuration or code, it just started working with the third Client ID and Client Secret.



来源:https://stackoverflow.com/questions/9290182/oauth-2-0-sample-error-when-accessing-google-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!