Module: Sinatra::AbstractAuthorization

Included in:
BasicAuthorization, DigestAuthorization
Defined in:
lib/amp/server/extension/authorization.rb

Overview

Code adapted from Ryan Tomayko and Christopher Schneid, shared under an MIT License Code significantly refactored for Amp

Instance Method Summary collapse

Instance Method Details

#authorized?Boolean Also known as: logged_in?

Convenience method to determine if a user is logged in

Returns:



21
22
23
# File 'lib/amp/server/extension/authorization.rb', line 21

def authorized?
  !!request.env['REMOTE_USER']
end

#bad_request!Object



16
17
18
# File 'lib/amp/server/extension/authorization.rb', line 16

def bad_request!
  throw :halt, [ 400, 'Bad Request' ]
end

#current_userObject

Name provided by the current user to log in



27
28
29
# File 'lib/amp/server/extension/authorization.rb', line 27

def current_user
  request.env['REMOTE_USER']
end

#unauthorized!(www_authenticate = challenge) ⇒ Object



11
12
13
14
# File 'lib/amp/server/extension/authorization.rb', line 11

def unauthorized!(www_authenticate = challenge)
  response["WWW-Authenticate"] = challenge
  throw :halt, [ 401, 'Authorization Required' ]
end