Authlogic Create new session without password

梦想与她 提交于 2019-12-11 03:31:49

问题


I'm trying to build Facebook OAuth into my existing Authlogic login system. I have the OAuth part complete, and stored the facebook access_token. The problem I'm facing is to actually log the user in (create a session) without the user typing in their password.

  #facebook's OAuth callback
  def callback 
    access_token = client.web_server.get_access_token(params[:code], :redirect_uri => redirect_uri)
    fb_user = JSON.parse(access_token.get('/me'))  
    @user = User.find_by_facebook_id(fb_user["id"]) || User.find_by_email(fb_user["email"]) || User.new
    @user.update_attributes({
      :facebook_id => fb_user["id"],
      :first_name => fb_user["first_name"],
      :last_name => fb_user["last_name"],
      :gender => fb_user["gender"],
      :email => fb_user["email"],
      :timezone => fb_user["timezone"],
      :locale => fb_user["locale"],
      :facebook_url => fb_user["link"],
      :facebook_access_token => access_token.token
    }) #unless @user.updated_at < 2.days.ago

# TODO: set current_user
# Maybe something like this?
   # @user_session = UserSession.new({
   #    :remember_me => true,
   #    :password =>"[FILTERED]",
   #    :email => email
   # }).save



  flash[:success] = "Welcome, #{@user.name}"
  redirect_to :root
end  

回答1:


Nevermind I figured it out. It was in the README the whole time.

UserSession.new(@user, true) //true = persistent session



来源:https://stackoverflow.com/questions/6730143/authlogic-create-new-session-without-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!