OpenSSL 証明書の作成、およびそれと Sinatra で実行される Webbrick サーバーの取得に関するチュートリアルとドキュメントを読みました。これはすべて機能しています-これに関する以前の投稿に感謝します。ただし、これをアプリに統合しようとすると、リクエストを解析して認証されたユーザー名を資格情報から引き出すことができる「実行前」コードが失われているようです。したがって、私の基本的な質問は、Rack::Auth::Basic と HTTPS の両方を、Sinatra と連携して実行されている WebBrick で同時に使用する方法です。これに関するヘルプは大歓迎です。
#!/usr/local/bin/ruby
require 'sinatra'
require 'webrick'
require 'webrick/https'
require 'openssl'
require 'yaml'
# basic authentication provided through Rack:Auth
configure do
  puts "configure do ran"
  # load password file - might move to DB at some point
  @@config = YAML.load_file(File.join(Dir.pwd, 'config', 'users.yml'))  
  use Rack::Auth::Basic, "Restricted Area" do |u, p|
    puts "use Rack::Auth::Basic"
    [u, p] == [u, @@config[:users][u][:password]]
  end
end
before do
  puts "before do ran"
  @auth ||=  Rack::Auth::Basic::Request.new(request.env)
  puts "auth username: " + @auth.username.to_s
  # set the user name for processing  in the post or get
  @myuser = @auth.username.to_s
end
class MyServer  < Sinatra::Base
  get '/' do
    # code would do something with @myuser here
    "Hello, world!"
  end       
end
pkey = cert = cert_name = nil
begin
  pkey = OpenSSL::PKey::RSA.new(File.open("private_key.pem").read)
  cert = OpenSSL::X509::Certificate.new(File.open("certificate.pem").read)
end
webrick_options = {
    :Port               => 8443,
    :Logger             => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG),
    :DocumentRoot       => "/ruby/htdocs",
    :SSLEnable          => true,
    :SSLVerifyClient    => OpenSSL::SSL::VERIFY_NONE,
    :SSLCertificate     => cert,
    :SSLPrivateKey      => pkey,
    :SSLCertName        => [ [ "CN",WEBrick::Utils::getservername ] ],
    :app                  => MyServer
}
Rack::Server.start webrick_options
繰り返しますが、これについての考えは大歓迎です。