【问题标题】:Devise not storing sessions and losing credentials after redirect设计在重定向后不存储会话并丢失凭据
【发布时间】:2013-11-05 14:40:37
【问题描述】:

这是一个非常奇怪的错误,我在 24 小时内一直在处理它。它运行良好,但突然开始失败。

问题: 当我想使用 Facebook 登录时,应用程序重定向到 Facebook 权限请求,返回,将更新保存在帐户模型(access_token 和 updated_at)中,但我被重定向到主页,没有访问已登录部分的权限。

我的堆栈是: Rails4,设计 3.0.0.rc,Omniauth,Omniauth-facebook 1.4.0。 该应用只接受使用 Facebook 登录。

看看:

Omniauth 控制器:account_signed_in? = 真

class Accounts::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def facebook
    # You need to implement the method below in your model (e.g. app/models/user.rb)
    @account = Account.find_for_facebook_oauth(request.env["omniauth.auth"], current_account)

    if @account.persisted?
      sign_in_and_redirect @account, :event => :authentication #this will throw if @user is not activated
      puts account_signed_in? # <-- true
      set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_account_registration_url
    end
  end

ApplicationController:account_signed_in? = 真

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  private
    def stored_location_for(resource_or_scope)
      nil
    end

    def after_sign_in_path_for(resource_or_scope)
      puts account_signed_in? # <-- true
      current_account.pages.empty? ? new_page_path : pages_path
    end

StaticController (home) account_signed_in? =假

class StaticController < ApplicationController

  def home
    puts account_signed_in? # <- false
    render layout: 'home'
  end 

我不知道是否有什么东西会干扰 Devise 和 Rails 之间正常的会话流程。

【问题讨论】:

    标签: session devise ruby-on-rails-4 omniauth warden


    【解决方案1】:

    找到了!

    由于 session_store.rb 中的 domain 参数,没有保存会话:

    BrainedPage::Application.config.session_store :cookie_store, 
      key: '_my_session', :domain => Rails.configuration.domain
    

    似乎我在开发环境中更改了域配置(添加了端口,因为我也将这个 var 用于其他提议),我没有意识到它可能产生的影响。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-17
      • 2013-01-06
      • 1970-01-01
      • 1970-01-01
      • 2014-03-31
      • 2013-06-19
      相关资源
      最近更新 更多