Skip to content

Instantly share code, notes, and snippets.

@samsm
Created July 11, 2012 20:28
Show Gist options
  • Save samsm/3093089 to your computer and use it in GitHub Desktop.
Save samsm/3093089 to your computer and use it in GitHub Desktop.
Authentication on middleware
class Ability
include CanCan::Ability
def initialize(user)
if user.admin?
can :manage, Resque
end
end
end
https://github.com/plataformatec/devise/
https://github.com/hassox/warden/
https://github.com/ryanb/cancan
https://github.com/defunkt/resque/
Foo::Application.routes.draw do
mount Resque::Server, :at => '/insecure'
# Devise gives us "authenticate", which we can use to secure this.
authenticate :user do
mount Resque::Server, :at => "/have-to-be-logged-in"
end
# CanCan gives us "constraints"
authenticate :user do
constraints(CanAccessResque) do
mount Resque::Server, :at => "/have-to-be-logged-in-and-authorized"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment