Sha256: 8503a36c06e6e53bf0a1e2bad77369073c5ee6683c7e1c016f403e0f4da80496
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
require 'devise/strategies/base' module Devise module Strategies # Sign in an user using HTTP authentication. class HttpAuthenticatable < Base def valid? request.authorization && mapping.to.respond_to?(:authenticate_with_http) end def authenticate! username, password = username_and_password if resource = mapping.to.authenticate_with_http(username, password) success!(resource) else custom!([401, custom_headers, ["HTTP Basic: Access denied.\n"]]) end end private def username_and_password decode_credentials(request).split(/:/, 2) end def decode_credentials(request) ActiveSupport::Base64.decode64(request.authorization.split(' ', 2).last || '') end def custom_headers { "Content-Type" => request.format.to_s, "WWW-Authenticate" => %(Basic realm="#{Devise.http_authentication_realm.gsub(/"/, "")}") } end end end end Warden::Strategies.add(:http_authenticatable, Devise::Strategies::HttpAuthenticatable)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
devise-1.1.pre2 | lib/devise/strategies/http_authenticatable.rb |