Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Devise to secure the delayed_job_web interface?

I'm using the delayed_job_web gem to monitor delayed jobs. https://github.com/ejschmitt/delayed_job_web

It is accessible using this line in my routes.rb:

match "/delayed_job" => DelayedJobWeb, :anchor => false

Every other area of my site requires a login using the Devise gem. How do I make this require a login too?

In the readme, they suggest adding the following to the config.rb:

if Rails.env.production?
  DelayedJobWeb.use Rack::Auth::Basic do |username, password|
    username == 'username'
    password == 'password'
  end
end

But that just uses plain text browser authentication.

UPDATE: I tried something similar to the railscast on resque, and I think it's on the verge of working but giving me a redirect loop now:

  authenticate :admin do
    mount DelayedJobWeb, :at => "/delayed_job"
  end

Any thoughts on why would it be giving a redirect loop?

Thanks,

like image 734
Ira Herman Avatar asked Aug 11 '12 07:08

Ira Herman


2 Answers

Use authenticated instead of authenticate as described here: http://excid3.com/blog/rails-tip-5-authenticated-root-and-dashboard-routes-with-devise/

Works for me!

like image 103
MMore Avatar answered Nov 12 '22 13:11

MMore


You could do something like this define this inside config/routes.rb file

  authenticate_user = lambda do |request|   
     request.env['warden'].authenticate?
  end

  constraints authenticate_user do
    mount DelayedJobWeb, :at => "/delayed_job"
  end

Alternately if you have cancan for any other role management library you could do it something like this

I have used both of this in my applications to control access to resque-web depending on the needs of the application

Hope this help

like image 43
Viren Avatar answered Nov 12 '22 15:11

Viren