0

我的代码曾经工作。将服务器移到新服务器后,突然我无法再使用 Google 帐户登录。我可以看到 google 向我显示了我的帐户列表,并且在我选择一个帐户后,google 将使用所有参数重定向到我的服务器。

这是我服务器上的日志。

method=GET path=/user/auth/google_oauth2/callback format=html controller=Users::OauthController action=failure status=302 duration=1.79 view=0.00 db=0.00 location=http://gokien.info/user/sign_in time=2020-12-09 14:35:39 +1100 remote_ip=123.123.123.123 params={"state"=>"the state", "code"=>"the code", "scope"=>"email profile openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile" , "authuser"=>"0", "prompt"=>"none" } user_id=referer=https://accounts.google.com/log_level=debug

这是我的 OauthController 代码

  1 class Users::OauthController < Devise::OmniauthCallbacksController
  2     rescue_from UserError::MissingEmailAddress,
  3         with: :missing_email_address
  4
  5     # This is the key method
  6     # used to authenticate user
  7     # after they are redirected from
  8     # Google login page
  9     def google_oauth2
 10         @user = User.from_omniauth(request.env[GK::Constants::OMNIAUTH_KEY    ])
 11         sign_in_and_redirect @user, event: :authentication
 12     end
 13
 14     def missing_email_address
 15         flash[:missing_email_address] = I18n.t 'loginPage.error.missingEma    ilAddress'
 16         redirect_to new_user_session_path
 17     end
 18
 19     # redirect after successful login with google or facebook
 20     # https://github.com/plataformatec/devise/wiki/How-To:-redirect-to-a-s    pecific-page-on-successful-sign-in
 21     def after_sign_in_path_for(resource)
 22         user_dashboard_path
 23     end
 24
 25
 26     alias_method :facebook, :google_oauth2
 27
 28 end

4

0 回答 0