11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rack::Auth::Basicで特定のパスは認証させない。

Last updated at Posted at 2015-03-23

Rack::Auth::Basicを使用してBasic認証を実装するとサイト全体に適用されます。

config.ru
use Rack::Auth::Basic do |username, password|
  username == "user" && password == "password"
end

例外的に/hogeのアクセスだけはBasic認証を適用したくない場合、
Rack::Auth::Basicを継承したクラスを作成し

config.ru
class MyAuth < Rack::Auth::Basic
  def call(env)
    request = Rack::Request.new(env)
    if request.path == '/hoge'
      @app.call(env)
    else
      super
    end
  end
end

useすることで/hogeアクセス時にはBasic認証が適用されません。

config.ru

use MyAuth do |username, password|
  username == "user" && password == "password"
end

11
9
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
11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?