简体   繁体   English

如何在Rails Metal中使用http基本身份验证?

[英]How to use http basic auth in Rails Metal?

I'm trying to implement http basic authentication in rails metal. 我正在尝试在Rails Metal中实现http基本身份验证。 Using this code: 使用此代码:

class Api
  def self.call(env)
    if env["PATH_INFO"] =~ /^\/client/

    Rack::Auth::Basic.new(env) do |user, password|
      raise 'ERROR'
    end

But this block never executed? 但是这个块从未执行过吗? Any help will be appreciated! 任何帮助将不胜感激!

Might I suggest this approach instead? 我可以建议采用这种方法吗? In your config/environments/yourenv.rb just add 在您的config / environments / yourenv.rb中添加

config.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Staging") do |u, p|
  u == ENV['HTTPUSER'] && p == ENV['HTTPPASS']
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Rails 2.2+中测试HTTP Basic Auth - Testing HTTP Basic Auth in Rails 2.2+ Rails以编程方式设置基本的http Auth凭据 - Rails set basic http Auth Credentials programatically 如何安装和使用Ruby on Rails金属生成器? - How to install and use the Ruby on Rails metal generator? 如果rails中未提供身份验证,请避免在http_basic_authenticate_with上使用HTTP 500 - Avoid HTTP 500 on http_basic_authenticate_with if no auth provided in rails 如何将 Cloudfront 与基本身份验证一起使用? - How to use Cloudfront with basic auth? 如何在Rails 5.2系统测试中填写或绕过HTTP Basic Auth? - How do you fill in or bypass HTTP Basic Auth in Rails 5.2 System Tests? 如何格式化POST以使用基本HTTP身份验证和设计Rails Gem创建用户 - How to format a POST to create User with Basic HTTP Auth and Devise Rails Gem Rails中的HTTP基本身份验证,同时禁用其他身份验证 - HTTP Basic Auth in Rails while disabling other authentication Rspec Rails 4.2.5使用基本的HTTP身份验证请求测试通过 - Rspec Rails 4.2.5 Request test pass with basic http auth Rails http GET请求,没有SSL验证和基本身份验证 - Rails http GET request with no ssl verification and basic auth
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM