小编Евг*_*чук的帖子

Ruby on Rails:我可以在约束中使用 http 基本身份验证吗?

我使用 Rails 5 API 模式

路线.rb:

Rails.application.routes.draw do      
  constraints Basic do
    mount Rswag::Ui::Engine  => '/api-docs'
    mount Rswag::Api::Engine => '/api-docs'
    mount Sidekiq::Web       => '/sidekiq'
    # etc
  end
end
Run Code Online (Sandbox Code Playgroud)

约束/基本.rb:

class Basic
  def self.matches?(request)
    authenticate_or_request_with_http_basic do |email, password|
      email == 'foo' && password = 'bar'
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误:

NoMethodError(Basic:Class 的未定义方法 `authenticate_or_request_with_http_basic')

我可以在约束中使用 http 基本身份验证吗?

ruby ruby-on-rails constraints basic-authentication

5
推荐指数
1
解决办法
2350
查看次数