Google OAuth 2.0 “error” : “redirect_uri_mismatch”

非 Y 不嫁゛ 提交于 2019-12-03 00:37:34
Hans Z.

The docs say in Step 1. https://developers.google.com/+/web/signin/server-side-flow#step_1_create_a_client_id_and_client_secret that there must be no redirect URIs configured, only "Authorized JavaScript origins". In the authorization request and the token exchange, the redirect_uri parameter value should be set to postmessage.

Edit: Prior art on this: Google OAuth 2 authorization - Error: redirect_uri_mismatch

Just ran into this problem myself. In my case, my credentials were set up for an installed application, NOT a web application. It seems that Installed applications cannot be configured with redirect URLs. I created a new credential as a web application, and this gave me the option to set a series of redirect urls.

Following the advice of this and other answers, I made sure the URL's matched (copy-paste) and this functioned correctly for me. I also did this in an Incognito Window.

The result was my browser being forwarded to the URL I put in the redirect_url parameter with a special query string parameter code populated with the code to use for the next step.

If seeing this when using the Google IAP, if you attempt to visit your URL in a browser, you'll get the message:

  1. That’s an error.

Error: redirect_uri_mismatch

The redirect URI in the request, [your_url]/_gcp_gatekeeper/authenticate, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/?project=[your_project_id]

if you visit the the URL it gives you (or indirectly via the console >> click edit on the correct "OAuth 2.0 client ID"), in the "Authorised redirect URIs" section, ensure you have the [your_url]/_gcp_gatekeeper/authenticate URL set.

The _gcp_gatekeeper/authenticate part is definitely required.

Google return the 400 error because of the mismatch in redirect URI.

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