Token
headers["WWW-Authenticate"] = %(Token realm="#{realm.gsub(/"/, "")}")authenticate_with_http_token
request_http_token_authentication
authenticate_or_request_with_http_tokenclass PostsController < ApplicationController
TOKEN = "secret"
before_action :authenticate, 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
private
def authenticate
# 使用验证
authenticate_or_request_with_http_token do |token, options|
token == TOKEN
end
end
end最后更新于