Module: Melodiest::Auth::Http

Defined in:
lib/melodiest/auth/http.rb

Overview

Instance Method Summary collapse

Instance Method Details

#authorized!(username = "admin", password = "admin") ⇒ Object



6
7
8
9
10
# File 'lib/melodiest/auth/http.rb', line 6

def authorized!(username="admin", password="admin")
  return if authorized?(username, password)
  headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"'
  halt 401, "Not authorized\n"
end

#authorized?(username, password) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/melodiest/auth/http.rb', line 12

def authorized?(username, password)
  @auth ||=  Rack::Auth::Basic::Request.new(request.env)
  @auth.provided? and @auth.basic? and @auth.credentials and @auth.credentials == [username, password]
end