[英]Omniauth_google_oauth2 Error: redirect_uri_mismatch
[英]Rails google_omniauth2 'error: redirect_uri_mismatch'
我一直在嘗試將google auth添加到我的注冊頁面,並按照指南中的步驟進行操作,但是登錄到google帳戶后,我被重定向到localhost:3000 /#,並且在控制台中出現以下錯誤:
E, [2018-01-02T18:21:05.351019 #57341] ERROR -- omniauth: (google_oauth2) Authentication failure! invalid_credentials: OAuth2::Error, redirect_uri_mismatch:
{“錯誤”:“ redirect_uri_mismatch”}
我已經嘗試了這個現有stackoverflow線程中的所有解決方案,但是對這些用戶有用的這些解決方案中沒有一個對我有用。
我的devise.rb:
Devise.setup do |config|
config.stretches = Rails.env.test? ? 1 : 11
config.extend_remember_period = true
config.password_length = 2..72
config.sign_out_all_scopes = false
config.sign_out_via = :get
OmniAuth.config.full_host = Rails.env.production? ?
'http://localhost:3000'
config.omniauth(:facebook,
Rails.application.secrets.facebook_app_id,
Rails.application.secrets.facebook_api_key,
image_size: :large)
config.omniauth(:google_oauth2,
Rails.application.secrets.google_client_id,
Rails.application.secrets.google_client_secret,
{:redirect_uri =>
"http://localhost:3000/users/auth/google_oauth2/callback"}
)
require('devise/orm/active_record')
end
的routes.rb
r.devise_for(:users,
only: :omniauth_callbacks,
controllers: {omniauth_callbacks: :omniauth})
我還向我的Google開發人員控制台添加了以下重定向uri:
https:// localhost:3000 / users / auth / google_oauth2 / callback https:// localhost:3000 / users / auth / google_oauth2 / callback / http:// localhost:3000 / users / auth / google_oauth2 / callback http://本地主機:3000 /用戶/認證/ google_oauth2 /回調/
預先感謝您的回答!
我的問題只在添加:name
選項時出現。 刪除后,效果如下所示:
config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"], {
:scope => "email, profile",
:prompt => "select_account",
:image_aspect_ratio => "square",
:image_size => 50
}
希望對大家有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.