Ruby on rails 在Rails API令牌身份验证中,领域是什么;申请书;www-Authenticate头的节?

Ruby on rails 在Rails API令牌身份验证中,领域是什么;申请书;www-Authenticate头的节?,ruby-on-rails,api,Ruby On Rails,Api,我有一个带有此控制器的rails应用程序: class EpisodesController < ApplicationController before_action :authenticate def index episodes = Episode.all render json: episodes, status: 200 end protected def authenticate authenticate_or_reque

我有一个带有此控制器的rails应用程序:

class EpisodesController < ApplicationController
  before_action :authenticate

  def index
    episodes = Episode.all
    render json: episodes, status: 200
  end

  protected
    def authenticate
      authenticate_or_request_with_http_token do |token, options|
        User.find_by(auth_token: token)
      end
    end
end
www-authenticate报头用于什么?这只是惯例吗?realm=“application”用于什么?我读到:

令牌部分表示给定资源使用令牌 认证。该URI下的资源当前是 “应用程序”领域。realm值允许保护资源 划分为不同的保护空间集,每个保护空间都有 自己的访问策略


但我不明白…

WWW-Authenticate头必须包含401个未经授权的响应(请参阅),因此这不仅仅是一个约定

通过该值,您可以指示支持哪种身份验证机制(在本例中,
令牌
,另一个身份验证方案可以是
Basic
,用于基本身份验证)。领域可以设置为您想要的任何值,并且应该标识安全区域。如果是基本身份验证,该值将显示在登录对话框上

$ curl -IH "Authorization: Token token=fake" http://localhost:3000/episodes.json
HTTP/1.1 401 Unauthorized 
Content-Type: text/html; charset=utf-8
WWW-Authenticate: Token realm="Application"