Module: Desviar::Auth
- Defined in:
- lib/auth.rb
Class 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 = Desviar::info) ⇒ Object
Class Method Details
.access_granted?(username, password) ⇒ Boolean
46 47 48 |
# File 'lib/auth.rb', line 46 def self.access_granted?(username, password) authenticated? || authenticate(username, password) end |
.authenticate(username, password) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/auth.rb', line 17 def self.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["desviar.authenticated"] = true request.env["REMOTE_USER"] = authentication.username else nil end end |
.authenticate! ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/auth.rb', line 38 def self.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
13 14 15 |
# File 'lib/auth.rb', line 13 def self.authenticated? request.env["REMOTE_USER"] && request.env["desviar.authenticated"] end |
.authentication ⇒ Object
9 10 11 |
# File 'lib/auth.rb', line 9 def self.authentication @authentication ||= Rack::Auth::Basic::Request.new request.env end |
.bad_request! ⇒ Object
34 35 36 |
# File 'lib/auth.rb', line 34 def self.bad_request! throw :halt, [ 400, "Bad Request" ] end |
.htpasswd ⇒ Object
5 6 7 |
# File 'lib/auth.rb', line 5 def self.htpasswd @htpasswd ||= Htpasswd.new(git.path_to("htpasswd")) end |