Class: Merb::AuthenticationMixin::BasicAuthentication
- Includes:
- ControllerExceptions
- Defined in:
- lib/merb-core/controller/mixins/authentication.rb
Constant Summary
Constants included from ControllerExceptions
ControllerExceptions::STATUS_CODES
Instance Method Summary collapse
- #authenticate(&authenticator) ⇒ Object
-
#initialize(controller, realm = "Application", &authenticator) ⇒ BasicAuthentication
constructor
A new instance of BasicAuthentication.
- #request ⇒ Object
Constructor Details
#initialize(controller, realm = "Application", &authenticator) ⇒ BasicAuthentication
Returns a new instance of BasicAuthentication.
58 59 60 61 62 |
# File 'lib/merb-core/controller/mixins/authentication.rb', line 58 def initialize(controller, realm = "Application", &authenticator) @controller = controller @realm = realm authenticate_or_request(&authenticator) if authenticator end |
Instance Method Details
#authenticate(&authenticator) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/merb-core/controller/mixins/authentication.rb', line 64 def authenticate(&authenticator) auth = Rack::Auth::Basic::Request.new(@controller.request.env) if auth.provided? and auth.basic? authenticator.call(*auth.credentials) else false end end |
#request ⇒ Object
74 75 76 77 |
# File 'lib/merb-core/controller/mixins/authentication.rb', line 74 def request @controller.headers['WWW-Authenticate'] = 'Basic realm="%s"' % @realm throw :halt, @controller.render("HTTP Basic: Access denied.\n", :status => Unauthorized.status, :layout => false) end |