Class: Sinatra::Helpers::Authentication
- Inherits:
-
Object
- Object
- Sinatra::Helpers::Authentication
- Defined in:
- lib/sinatra/basic_auth.rb
Instance Attribute Summary (collapse)
-
- (Object) app
Returns the value of attribute app.
-
- (Object) request
Returns the value of attribute request.
Instance Method Summary (collapse)
- - (Object) auth
- - (Object) authorize(username, password)
- - (Boolean) authorized?
- - (Object) bad_request!
-
- (Authentication) initialize(app, request)
constructor
A new instance of Authentication.
- - (Object) unauthorized!
Constructor Details
- (Authentication) initialize(app, request)
A new instance of Authentication
25 26 27 28 |
# File 'lib/sinatra/basic_auth.rb', line 25 def initialize( app, request ) self.app = app self.request = request end |
Instance Attribute Details
- (Object) app
Returns the value of attribute app
24 25 26 |
# File 'lib/sinatra/basic_auth.rb', line 24 def app @app end |
- (Object) request
Returns the value of attribute request
24 25 26 |
# File 'lib/sinatra/basic_auth.rb', line 24 def request @request end |
Instance Method Details
- (Object) auth
30 31 32 |
# File 'lib/sinatra/basic_auth.rb', line 30 def auth @basic_auth ||= Rack::Auth::Basic::Request.new( request.env ) end |
- (Object) authorize(username, password)
47 48 49 50 |
# File 'lib/sinatra/basic_auth.rb', line 47 def ( username, password ) settings.basic_auth_username == username && settings.basic_auth_password == password end |
- (Boolean) authorized?
43 44 45 |
# File 'lib/sinatra/basic_auth.rb', line 43 def request.env['REMOTE_USER'] end |
- (Object) bad_request!
39 40 41 |
# File 'lib/sinatra/basic_auth.rb', line 39 def bad_request! throw :halt, [ 400, 'Bad Request' ] end |
- (Object) unauthorized!
34 35 36 37 |
# File 'lib/sinatra/basic_auth.rb', line 34 def app.headers 'WWW-Authenticate' => %(Basic realm="#{settings.basic_auth_realm}") throw :halt, [ 401, 'Authorization Required' ] end |