Class: Gollum::Auth::App

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

Instance Method Summary collapse

Constructor Details

#initialize(app, users, opts = { }) ⇒ App

Returns a new instance of App.



15
16
17
18
19
# File 'lib/gollum/auth.rb', line 15

def initialize(app, users, opts = { })
  @app = app
  users.each { |args| User.new(args).save! }
  @opts = { allow_unauthenticated_readonly: false }.merge(opts)
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gollum/auth.rb', line 21

def call(env)
  request = Request.new(env)
  if request.requires_authentication?(@opts[:allow_unauthenticated_readonly])
    auth = Rack::Auth::Basic::Request.new(env)
    if auth.provided? && auth.basic? && user = User.find_by_credentials(auth.credentials)
      request.store_author_in_session(user)
    else
      return not_authorized
    end
  end
  @app.call(env)
end