LoginSignup
3
3

More than 5 years have passed since last update.

gollumで特定のディレクトリのみBasic認証をかける

Posted at

gollum、というかSinatraのはなし。--configで渡すファイルに以下のような感じで記述する。


module Precious
  class App < Sinatra::Base
    enable :logging

    before '/private/*' do
      response['WWW-Authenticate'] = %(Basic realm="private area.")
      throw(:halt, [401, "Not authorized\n"]) unless private_authorized?
      show_page_or_file("/private/#{params[:splat].first}")
    end

    def private_authorized?
      @auth ||=  Rack::Auth::Basic::Request.new(request.env)
      @auth.credentials == ['user', 'pass']               #=> username, password
    end
  end
end

3
3
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
3
3