module Sinatra::Protection

Constants

VERSION

Public Instance Methods

authorized?() click to toggle source
# File lib/sinatra/protection.rb, line 21
def authorized?
  @auth ||=  Rack::Auth::Basic::Request.new(request.env)
  @auth.provided? and @auth.basic? and @auth.credentials and @auth.credentials == [settings.username, settings.password]
end
protected!() click to toggle source
# File lib/sinatra/protection.rb, line 14
def protected!
  return unless settings.enable_protection
  return if authorized?
  headers['WWW-Authenticate'] = "Basic realm=\"#{settings.realm}\""
  halt 401, "Not authorized\n"
end