【问题标题】:Rails: Google authentication with AuthlogicRails:使用 Authlogic 进行 Google 身份验证
【发布时间】:2018-08-29 11:46:52
【问题描述】:

我正在使用 Authlogic,我想将 google 身份验证与 Authlogic 一起实施到现有项目中。我找不到任何好的来源。我尝试使用openid 和authlogic-oauth,它们似乎不起作用。是否有任何替代宝石/方法可以与 Authlogic 一起用于 Google 身份验证? 谢谢

【问题讨论】:

标签: ruby-on-rails authlogic


【解决方案1】:

我有点晚发布这个答案。在这里,我们必须找到在omniauth info 中是否显示了特定的电子邮件。如果存在,则按照我们为 authlogic 身份验证所遵循的正常步骤进行操作。这有点棘手但很容易。为此,我们不需要任何第三方库。所以我们可以用下面的 gem 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-07
    • 2017-03-11
    • 1970-01-01
    • 2018-10-19
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    • 2019-08-15
    相关资源
    最近更新 更多