Rails 5保护Sidekiq UI

时间:2017-07-17 03:14:56

标签: ruby-on-rails devise sidekiq

我正在尝试用Devise保护Sidekiq UI。我正在运行Rails 5.1,Devise 4.3和Sidekiq 5.0。我尝试了以下帖子:

How can I password-protect my /sidekiq route (i.e. require authentication for the Sidekiq::Web tool)?

但是我收到以下错误:

Undefined method failure_app for nil:NilClass

我的路线文件如下所示:

Rails.application.routes.draw do
  constraint = lambda do |request|
    request.env['warden'].authenticate!({ scope: :admin_user })
  end

  constraints constraint do
    mount Sidekiq::Web => '/admin/sidekiq'
  end

  devise_for :users
  resources :users
end

如何使用Devise on Rails 5.1保护Sidekiq UI?

1 个答案:

答案 0 :(得分:1)

我偶然发现了page,其中概述了如何使用Devise保护Web UI:

Devise

Allow any authenticated User

# Allow any user access
authenticate :user do
  mount Sidekiq::Web => '/sidekiq'
end

# Allow only admin users
authenticate :user, lambda { |u| u.admin? } do
  mount Sidekiq::Web => '/sidekiq'
end

我已经确认这适用于Rails 5.1和Devise 4.3。