OmniAuth before_filter要求登录

时间:2010-12-18 10:56:48

标签: ruby-on-rails omniauth

是否可以使用OmniAuth在某些操作之前要求登录?

我从轨道广播中记得Devise有一个before_filter,但是OmniAuth呢?

1 个答案:

答案 0 :(得分:10)

您可以添加before_filter

class ApplicationController < ActionController::Base

  before_filter :authenticate

  def authenticate
    redirect_to :login unless User.find_by_provider_and_uid(auth["provider"], auth["uid"])
  end
...
end

假设: 1.您已经定义了一个包含以下链接的登录页面:<%= link_to "Sign in with Facebook", "/auth/facebook" %>

另见RailsCasts tagged with authentication