Basic
对应头部字段及内容:
headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub(/"/, "")}")类方法:
http_basic_authenticate_with使用举例:
class PostsController < ApplicationController
http_basic_authenticate_with name: "dhh", password: "secret", except: :index
def index
render plain: "Everyone can see me!"
end
def edit
render plain: "I'm only accessible if you know the password"
end
endhttp_basic_authenticate_with 除 :name 和 :password 选项外,一般还可设置 :realm 做为提示信息。它已经封装了 authenticate_or_request_with_http_basic 方法。
http_basic_authenticate_with 最常用的验证方式。
Controller 方法:
authenticate_or_request_with_http_basic 简单的封装了其余两个方法。
使用举例:
其它方法:
使用举例:
最后更新于
这有帮助吗?