Module: Git::Webby::AuthenticationHelpers

Defined in:
lib/git/webby.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#access_granted?(username, password) ⇒ Boolean

Returns:

  • (Boolean)


236
237
238
# File 'lib/git/webby.rb', line 236

def access_granted?(username, password)
  authenticated? || authenticate(username, password)
end

#authenticate(username, password) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
# File 'lib/git/webby.rb', line 207

def authenticate(username, password)
  checked   = [ username, password ] == authentication.credentials
  validated = authentication.provided? && authentication.basic?
  granted   = htpasswd.authenticated? username, password
  if checked and validated and granted
    request.env["git.webby.authenticated"] = true
    request.env["REMOTE_USER"] = authentication.username
  else
    nil
  end
end

#authenticate!Object



228
229
230
231
232
233
234
# File 'lib/git/webby.rb', line 228

def authenticate!
  return if authenticated?
  unauthorized! unless authentication.provided?
  bad_request!  unless authentication.basic?
  unauthorized! unless authenticate(*authentication.credentials)
  request.env["REMOTE_USER"] = authentication.username
end

#authenticated?Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/git/webby.rb', line 203

def authenticated?
  request.env["REMOTE_USER"] && request.env["git.webby.authenticated"]
end

#authenticationObject



199
200
201
# File 'lib/git/webby.rb', line 199

def authentication
  @authentication ||= Rack::Auth::Basic::Request.new request.env
end

#bad_request!Object



224
225
226
# File 'lib/git/webby.rb', line 224

def bad_request!
  throw :halt, [ 400, "Bad Request" ]
end

#htpasswdObject



195
196
197
# File 'lib/git/webby.rb', line 195

def htpasswd
  @htpasswd ||= Htpasswd.new(git.path_to("htpasswd"))
end

#unauthorized!(realm = Git::Webby::info) ⇒ Object



219
220
221
222
# File 'lib/git/webby.rb', line 219

def unauthorized!(realm = Git::Webby::info)
  headers "WWW-Authenticate" => %(Basic realm="#{realm}")
  throw :halt, [ 401, "Authorization Required" ]
end