Class: Desviar::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/auth.rb

Instance Method Summary collapse

Constructor Details

#initialize(htdigest_file, adminuser, realm, authsalt) ⇒ Auth

Returns a new instance of Auth.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/auth.rb', line 13

def initialize(htdigest_file, adminuser, realm, authsalt)
  @users = Hash.new
  File.open(htdigest_file) do |f|
    f.each_line do |line|
      if line.split(':')[1] == realm
        @users[line.split(':')[0]] = line.split(':')[2].strip
      end
    end
  end
  @realm     = realm
  @adminuser = adminuser
  @authsalt  = authsalt
end

Instance Method Details

#authenticate!(app) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/auth.rb', line 27

def authenticate!(app)
  auth = Rack::Auth::Digest::MD5.new(app) do |username|
    @users[username]
  end
  auth.realm  = @realm
  auth.opaque = @authsalt
  auth.passwords_hashed = true
  auth
end