我正在使用Authlogic,我想与Authlogic一起在现有项目中实施google身份验证。我找不到任何好的来源。我尝试使用openid
和authlogic-oauth
,它们似乎不起作用。是否有其他可与Authlogic一起用于Google身份验证的宝石/方法?
谢谢
答案 0 :(得分:0)
我为此发布答案有点晚了。在这里,我们必须找到omniauth信息中是否显示了特定的电子邮件。如果存在,那么请遵循我们为authlogic身份验证遵循的常规步骤。这有点棘手,但很容易。为此,我们不需要任何第三方库。因此,我们可以使用以下 omniauth-google-oauth2 和 authlogic
来完成此操作 class AuthenticationsController < ApplicationController
def create
omniauth = request.env['omniauth.auth']
if omniauth["provider"] == "google_oauth2"
user = User.find_by_email(email)
@user_session = UserSession.new(user)
if @user_session.save
flash[:success] = "Login successful!"
redirect_to session[:return_to] ||= markets_url
else
flash[:error] = "Your Account doesn't exists. Please contact
Xxxxx support."
redirect_to :login
end
end
end