| Module | Capcode::Helpers::Authorization |
| In: |
lib/capcode/helpers/auth.rb
|
Allow you to add and HTTP Authentication (Basic or Digest) to a controller
Options :
The block must return a Hash of username => password like that :
{
"user1" => "pass1",
"user2" => "pass2",
# ...
}
# File lib/capcode/helpers/auth.rb, line 106
106: def http_authentication( opts = {}, &b )
107: @auth = nil
108:
109: @auth_type = opts[:type]||:basic
110: realm = opts[:realm]||"Capcode.app"
111: opaque = opts[:opaque]||"opaque"
112: @authorizations = b
113:
114: return if authorized?
115:
116: if @auth_type == :basic
117: basic_unauthorized!(realm) unless auth.provided?
118: bad_request! unless auth.basic?
119: basic_unauthorized!(realm) unless basic_authorize(*auth.credentials)
120: else
121: digest_unauthorized!(realm, opaque) unless auth.provided?
122: bad_request! unless auth.digest?
123: digest_unauthorized!(realm, opaque) unless digest_authorize
124: end
125:
126: request.env['REMOTE_USER'] = auth.username
127: end