开发者

How to use http basic auth in Rails Metal?

I'm trying to implement http basic authentication in rails metal. Using this code:

class Api
  def self.call(env)
    if env["PATH_INFO"] =~ /^开发者_StackOverflow中文版\/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.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Staging") do |u, p|
  u == ENV['HTTPUSER'] && p == ENV['HTTPPASS']
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜