Module: Webmachine::Resource::Authentication
- Defined in:
- lib/webmachine/resource/authentication.rb
Overview
Helper methods that can be included in your
Webmachine::Resource to assist in performing HTTP
Authentication.
Constant Summary
- BASIC_HEADER =
Pattern for matching Authorization headers that use the Basic auth scheme.
/^Basic (.*)$/i.freeze
Instance Method Summary (collapse)
-
- (true, String) basic_auth(header, realm = "Webmachine") {|user, password| ... }
A simple implementation of HTTP Basic auth.
Instance Method Details
- (true, String) basic_auth(header, realm = "Webmachine") {|user, password| ... }
A simple implementation of HTTP Basic auth. Call this from the
Callbacks#is_authorized? callback,
giving it a block which will be yielded the username and
password and return true or false.
26 27 28 29 30 31 32 |
# File 'lib/webmachine/resource/authentication.rb', line 26 def basic_auth(header, realm="Webmachine") if header =~ BASIC_HEADER && (yield *$1.unpack('m*').first.split(/:/,2)) true else %Q[Basic realm="#{realm}"] end end |