Module: Git::Lighttp::AuthenticationHelpers
- Defined in:
- lib/git/lighttp.rb
Overview
:nodoc:
Instance Method Summary collapse
- #access_granted?(username, password) ⇒ Boolean
- #authenticate(username, password) ⇒ Object
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
- #authentication ⇒ Object
- #bad_request! ⇒ Object
- #htpasswd ⇒ Object
- #unauthorized!(realm = Git::Lighttp.info) ⇒ Object
Instance Method Details
#access_granted?(username, password) ⇒ Boolean
307 308 309 |
# File 'lib/git/lighttp.rb', line 307 def access_granted?(username, password) authenticated? || authenticate(username, password) end |
#authenticate(username, password) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/git/lighttp.rb', line 278 def authenticate(username, password) checked = [username, password] == authentication.credentials validated = authentication.provided? && authentication.basic? granted = htpasswd.authenticated? username, password if checked && validated && granted request.env['git.lighttp.authenticated'] = true request.env['REMOTE_USER'] = authentication.username else false end end |
#authenticate! ⇒ Object
299 300 301 302 303 304 305 |
# File 'lib/git/lighttp.rb', line 299 def authenticate! return if authenticated? unless authentication.provided? bad_request! unless authentication.basic? unless authenticate(*authentication.credentials) request.env['REMOTE_USER'] = authentication.username end |
#authenticated? ⇒ Boolean
274 275 276 |
# File 'lib/git/lighttp.rb', line 274 def authenticated? request.env['REMOTE_USER'] && request.env['git.lighttp.authenticated'] end |
#authentication ⇒ Object
270 271 272 |
# File 'lib/git/lighttp.rb', line 270 def authentication @authentication ||= Rack::Auth::Basic::Request.new request.env end |
#bad_request! ⇒ Object
295 296 297 |
# File 'lib/git/lighttp.rb', line 295 def bad_request! throw :halt, [400, 'Bad Request'] end |
#htpasswd ⇒ Object
266 267 268 |
# File 'lib/git/lighttp.rb', line 266 def htpasswd @htpasswd ||= Htpasswd.new(git.path_to('htpasswd')) end |
#unauthorized!(realm = Git::Lighttp.info) ⇒ Object
290 291 292 293 |
# File 'lib/git/lighttp.rb', line 290 def (realm = Git::Lighttp.info) headers 'WWW-Authenticate' => %(Basic realm="#{realm}") throw :halt, [401, 'Authorization Required'] end |