LoginSignup
5
4

More than 5 years have passed since last update.

RailsでBASIC認証機能を追加する (heroku向け)

Last updated at Posted at 2014-12-08

application_controller.rb に以下を入れれば一発

application_controller.rb
class ApplicationController

  before_filter :basic_auth_filter

  private

    def basic_auth_filter
      return true if ENV['ENABLE_BASIC_AUTH'].to_i != 1

      authenticate_or_request_with_http_basic do |username, password|
        username == ENV['BASIC_AUTH_ID'] &&
        password == ENV['BASIC_AUTH_PASS']
      end
    end
end

で以下で設定

heroku config:set **** -a [YOUR-HEAOKU-APP]

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4