Module: Backstage::Authentication
- Defined in:
- lib/authentication.rb
Instance Method Summary collapse
- #auth ⇒ Object
- #authenticate(username, password) ⇒ Object
- #authenticated? ⇒ Boolean
- #bad_request! ⇒ Object
- #login_path ⇒ Object
- #require_authentication ⇒ Object
- #skip_authentication ⇒ Object
- #unauthorized!(realm = request.host) ⇒ Object
Instance Method Details
#auth ⇒ Object
23 24 25 |
# File 'lib/authentication.rb', line 23 def auth @auth ||= Rack::Auth::Basic::Request.new(request.env) end |
#authenticate(username, password) ⇒ Object
44 45 46 47 48 |
# File 'lib/authentication.rb', line 44 def authenticate(username, password) return false if username.nil? || password.nil? authenticator = TorqueBox::Authentication['backstage'] authenticator.authenticate(username, password) end |
#authenticated? ⇒ Boolean
40 41 42 |
# File 'lib/authentication.rb', line 40 def authenticated? !request.env['REMOTE_USER'].nil? end |
#bad_request! ⇒ Object
32 33 34 |
# File 'lib/authentication.rb', line 32 def bad_request! throw :halt, [ 400, 'Bad Request' ] end |
#login_path ⇒ Object
36 37 38 |
# File 'lib/authentication.rb', line 36 def login_path "#{request.script_name}/login" end |
#require_authentication ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/authentication.rb', line 54 def require_authentication return if request.env['SKIP_AUTH'] return if authenticated? unless auth.provided? bad_request! unless auth.basic? unless authenticate(*auth.credentials) request.env['REMOTE_USER'] = auth.username end |
#skip_authentication ⇒ Object
50 51 52 |
# File 'lib/authentication.rb', line 50 def skip_authentication request.env['SKIP_AUTH'] = true end |
#unauthorized!(realm = request.host) ⇒ Object
27 28 29 30 |
# File 'lib/authentication.rb', line 27 def (realm=request.host) headers 'WWW-Authenticate' => %(Basic realm="#{realm}") throw :halt, [ 401, 'Authentication Required' ] end |