![](/img/trans.png)
[英]Google OAuth 2.0 and Devise - “error” : “redirect_uri_mismatch”
[英]Getting “Error: redirect_uri_mismatch” with google_oauth2
網址似乎正確(昨天上次更新):
文件也是:
omniauth.rb:
provider :google_oauth2, 'MY_CLIENT_ID.apps.googleusercontent.com', 'MY_CLIENT_SECRET',
:scope => 'https://mail.google.com/mail/feed/atom/'
Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:3000/auth/google_oauth2/callback did not match a registered redirect URI
header.html.erb
<li><%= link_to "Sign in with Google", "auth/google_oauth2" %></li>
routes.rb中:
match '/auth/:provider/callback', to: 'sessions#omniauth_create'
但是我得到了這個:
> Error: redirect_uri_mismatch The redirect URI in the request:
> http://localhost:3000/auth/google_oauth2/callback did not match a
> registered redirect URI
(Twitter和Facebook OmniAuth工作正常)
不確定是什么問題。 有什么好處可以解決這個問題嗎?
編輯
我將URI更改為http
...:
但仍然得到同樣的錯誤。
看起來請求正在點擊http://localhost:3000/auth/google_oauth2/callback
,但是您指定的與類似模式匹配的重定向URI是針對https
。 將http://localhost:3000/auth/google_oauth2/callback
到重定向列表可能會解決該問題。
編輯:另一個潛在的修復是在相應的重定向URI中包含一個尾隨/
,在這種情況下似乎有效。
omniauth-oauth2
gem版本1.4
有一個相對新鮮的問題https://github.com/intridea/omniauth-oauth2/issues/81#issuecomment-151038559
臨時修復是在Gemfile
明確降級該gem
gem 'omniauth-oauth2', '~> 1.3.1'
FOO
vi config / initializers / omniauth.rb OmniAuth.config.full_host = 'https://localhost:3000' Rails.application.config.middleware.use OmniAuth::Builder do provider :google_oauth2, 'google_client_id', 'google_client_secret' end
分享一個非常簡單的復制粘貼解決方案,對我有用。
我將我在代碼中指定的任何內容復制為redirectUri
即"redirect_uri": "http://127.0.0.1:3001/"
並將此key
的value
粘貼到要求授權重定向URI的Google設置中。 這樣我就確保兩個參數都相同。
如果url
是計算的,我會console.log()
它。並在控制台窗口中復制它,然后將其粘貼到谷歌設置中。
我嘗試了以上所有但是沒有為我工作。 最后在我的錯誤消息中注意到我的回電略有不同。 我在localhost:3000和auth之間有一個用戶。 不確定為什么。
http://localhost:3000/users/auth/google_oauth2/callback
換了它,等了30分鍾就行了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.