maeshimaの日記

メモ書きです

request_http_basic_authenticationメソッド

request_http_basic_authenticationメソッドは、メソッドの名前からbasic認証を始めるメソッドかと思ったけど違った。

def request_http_basic_authentication(realm = "Application")
  HttpAuthentication::Basic.authentication_request(self, realm)
end
def authentication_request(controller, realm)
  controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub(/"/, "")}")
  controller.__send__ :render, :text => "HTTP Basic: Access denied.\n", :status => :unauthorized
end

basic認証してね☆と401を返すメソッドだった

追記

たぶん401返したときに、ブラウザ側でユーザ名をパスワードを入力させるような挙動になるんだと思う