6

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

我记得在 Railscast 中,Devise 有一个 before_filter,但是 OmniAuth 呢?

4

1 回答 1

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

于 2010-12-18T11:09:35.690 回答