Harbor::Auth::Basic
Simple mechanism for implementing HTTP basic authentication.
get("/secret-page") do |request, response|
Harbor::Auth::Basic.authenticate(request, response) { |username, password| username == "wieck" }
response.puts "Secret Stuff"
end
Parent
Attributes
Public Class Methods
authenticate(request, response)
Checks the credentials provided in the request against the provided block. If the block returns false, the request aborted.
# File lib/harbor/auth/basic.rb, line 22 22: def self.authenticate(request, response) #:yields: username, password 23: auth = new(request) 24: 25: unless auth.provided? && yield(auth.credentials) 26: response.headers["WWW-Authenticate"] = 'Basic realm="%s"' % auth.realm 27: response.unauthorized! 28: end 29: end