Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OmniAuth before_filter for requiring login

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?

like image 796
Martin Petrov Avatar asked Dec 18 '10 10:12

Martin Petrov


1 Answers

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

like image 81
Zabba Avatar answered Oct 19 '22 22:10

Zabba