Question

is it possible using OmniAuth to require login before certain actions?

I remember from a railscast that Devise has a before_filter, but does OmniAuth?

Was it helpful?

Solution

You can add a 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

Presuming: 1. You have defined a login page with link(s) like : <%= link_to "Sign in with Facebook", "/auth/facebook" %>

See also RailsCasts tagged with authentication

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top