【发布时间】: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