I’m writting a small app that requires basic authentication in Sinatra.
I followed the advice of the official Sinatra faq
(http://www.sinatrarb.com/faq.html#auth) and have implemented this code
require 'rubygems' require 'sinatra' helpers do def protected! response['WWW-Authenticate'] = %(Basic realm="Testing HTTP Auth") and \ throw(:halt, [401, "Not authorized\n"]) and \ return unless authorized? end def authorized? @auth ||= Rack::Auth::Basic::Request.new(request.env) @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'admin'] end end get '/' do "Everybody can see this page" end get '/protected' do protected! "Welcome, authenticated client" end
So I get a window asking me to ender my credentials when going to
/protected and it logs me in. Once logged in though, I would like to be
able to log out. I know the solution to this must be super easy but I
just can’t get it to work.
Any help is greatly appreciated. Thanks!