flagman
flagman

Reputation: 502

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"] =~ /^\/client/

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

But this block never executed? Any help will be appreciated!

Upvotes: 1

Views: 1355

Answers (1)

ybakos
ybakos

Reputation: 8630

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

Upvotes: 3

Related Questions