Module: Sinatra::Authorization::Helpers
- Defined in:
- lib/sinatra/authorization.rb
Instance Method Summary collapse
-
#authorization_realm ⇒ Object
From you app, call set :authorization_realm, “my app” to set this or define a #authorization_realm method in your helpers block.
-
#authorize(username, password) ⇒ Object
Redefine this method on your helpers block to actually contain your authorization logic.
-
#authorized? ⇒ Boolean
(also: #logged_in?)
Convenience method to determine if a user is logged in.
-
#current_user ⇒ Object
Name provided by the current user to log in.
-
#login_required ⇒ Object
Call in any event that requires authentication.
Instance Method Details
#authorization_realm ⇒ Object
From you app, call set :authorization_realm, “my app” to set this or define a #authorization_realm method in your helpers block.
25 26 27 |
# File 'lib/sinatra/authorization.rb', line 25 def . end |
#authorize(username, password) ⇒ Object
Redefine this method on your helpers block to actually contain your authorization logic.
19 20 21 |
# File 'lib/sinatra/authorization.rb', line 19 def (username, password) false end |
#authorized? ⇒ Boolean Also known as: logged_in?
Convenience method to determine if a user is logged in
39 40 41 |
# File 'lib/sinatra/authorization.rb', line 39 def !!current_user end |
#current_user ⇒ Object
Name provided by the current user to log in
45 46 47 48 49 |
# File 'lib/sinatra/authorization.rb', line 45 def current_user request.env['REMOTE_USER'] = auth.username if auth.provided? && auth.basic? && (*auth.credentials) request.env['REMOTE_USER'] end |
#login_required ⇒ Object
Call in any event that requires authentication
30 31 32 33 34 35 36 |
# File 'lib/sinatra/authorization.rb', line 30 def login_required return if unless auth.provided? bad_request! unless auth.basic? unless (*auth.credentials) request.env['REMOTE_USER'] = auth.username end |