Google OAuth 2 authorization - Error: redirect_uri

2018-12-31 10:24发布

On the website https://code.google.com/apis/console I have registered my application, set up generated Client ID: and Client Secret to my app and tried to log in with Google. Unfortunately, I got the error message:

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

What does mean this message, and how can I fix it? I use the gem omniauth-google-oauth2.

30条回答
春风洒进眼中
2楼-- · 2018-12-31 10:51

Rails users (from the omniauth-google-oauth2 docs):

Fixing Protocol Mismatch for redirect_uri in Rails

Just set the full_host in OmniAuth based on the Rails.env.

# config/initializers/omniauth.rb

OmniAuth.config.full_host = Rails.env.production? ? 'https://domain.com' : 'http://localhost:3000'

REMEMBER: Do not include the trailing "/"

查看更多
只若初见
3楼-- · 2018-12-31 10:51

for me it was because in the 'Authorized redirect URIs' list I've incorrectly put https://developers.google.com/oauthplayground/ instead of https://developers.google.com/oauthplayground (without / at the end).

查看更多
像晚风撩人
4楼-- · 2018-12-31 10:53

This seems quite strange and annoying that no "one" solution is there. for me http://localhost:8000 did not worked out but http://localhost:8000/ worked out.

查看更多
无色无味的生活
5楼-- · 2018-12-31 10:53

When you register your app at https://code.google.com/apis/console and make a Client ID, you get a chance to specify one or more redirect URIs. The value of the redirect_uri parameter on your auth URI has to match one of them exactly.

查看更多
伤终究还是伤i
6楼-- · 2018-12-31 10:53

Checklist:

  • http or https?
  • & or &?
  • trailing slash(/) or open ?
  • (CMD/CTRL)+F, search for the exact match in the credential page. If not found then search for the missing one.
  • Wait until google refresh it. May happen in each half an hour if you are changing frequently or it may stay in pool. For my case it was almost half an hour to take effect.
查看更多
梦该遗忘
7楼-- · 2018-12-31 10:53

I had the same issue with google sign in, I was about to pull my hairs!!! I had correctly entered my callbacks in google Credential panel at google developer console here was my redirect urls :

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

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

https://www.example.com/oauth2callback

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

every thing seems fine right? but it still didn't work until I added one more magical Url I added signin-google url (which is default google callback) without www and problem solved.

take it into account (depending of you domain) you may or may not need to add both with and without www urls

查看更多
登录 后发表回答