active_adminにベーシック認証をかける

# application_controller
http_basic_authenticate_with :name => "hoge", :password => "hoge", :if => :admin_controller?
def admin_controller?
self.class < ActiveAdmin::BaseController
end

これだと管理者ログイン画面にベーシック認証がかかりません。

# application_controller
def authenticate_admin
authenticate_or_request_with_http_basic('Admin') do |name, password|
name == 'hogei' && password == 'hoge'
end
end
# config/initializers/active_admin.rb
config.authentication_method = :authenticate_admin

これでも管理者ログイン画面にベーシック認証がかかりません。

結局上で定義したアクションをconfig/initializers/active_admin.rbの
before_actionで呼べばOKでした。

# config/initializers/active_admin.rb
config.before_action :authenticate_admin

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です