| 2008-06-16 14:34:28 | Ответить |
|---|---|
|
Dracula Адрес: Сообщений: 23 Регистр: 2008-05-31 его блог 0 сообщ. |
RE: Ruby CGI - Basic Authorization |
|
Большое спасибо Равилю за оказанную помощь в реализации этого примера:
Пример Ruby CGI Basic Authorization логин и пароль - 'test' --------------------------------------- Добавьте это в свой .htaccess RewriteEngine on RewriteCond %{HTTP:Authorization} ^(.*) RewriteRule ^(.*) - [E=HTTP_CGI_AUTHORIZATION:%1] --------------------------------------- index.rb --------------------------------------- #!c:/ruby/bin/ruby.exe $kcode = "windows-1251" require 'cgi' cgi = CGI.new 'html4' auth_type, credentials = ENV['HTTP_CGI_AUTHORIZATION'].split(' ') if auth_type == 'Basic' && (user, pass = credentials.unpack('m*').first.split(':', 2)) && user == 'test' && pass = 'test' cgi.out { cgi.html { cgi.body { cgi.h2 { "Логин: #{user}" } + cgi.h2 { "Пароль: #{pass}" } } } } else cgi.out("Status" => "401 Authorization Required", "Type" => "text/html", "WWW-Authenticate" => 'Basic realm="Web Password"') do "401 Authorization Required" end end |
|
| basic authorization, cgi, ruby, working example basic authorization |