Sha256: 63e65b20563f39a29994440b6c8b1f7ff85456978093931da1f30313fdcacf72
Contents?: true
Size: 883 Bytes
Versions: 1
Compression:
Stored size: 883 Bytes
Contents
require 'rack' require 'webrick/httpauth/htpasswd' module TDiary module Rack class Auth class PasswordFileNotFound < StandardError; end class Basic def initialize(app, file = '.htpasswd') @authenticator = ::Rack::Auth::Basic.new(app) do |user, pass| unless File.exist?(file) raise PasswordFileNotFound.new("#{file} is not found. Please create it by htpasswd program.") end htpasswd = WEBrick::HTTPAuth::Htpasswd.new(file) crypted = htpasswd.get_passwd(nil, user, false) crypted == pass.crypt(crypted) if crypted end end def call(env) begin @authenticator.call(env) rescue PasswordFileNotFound => e [403, {"content-type" => "text/plain"}, [e.message]] end end end end end end # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End:
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tdiary-5.3.0 | lib/tdiary/rack/auth/basic.rb |