Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make sure authorization headers include "Basic".

  • Loading branch information...
commit 48d4a40efb810540abcd22f4a1769624377e4748 1 parent 589ad31
@benubois benubois authored
Showing with 15 additions and 0 deletions.
  1. +3 −0  config/application.rb
  2. +12 −0 lib/basic_authentication.rb
View
3  config/application.rb
@@ -1,6 +1,7 @@
require File.expand_path('../boot', __FILE__)
require 'rails/all'
+require_relative '../lib/basic_authentication'
# Assets should be precompiled for production (so we don't need the gems loaded then)
Bundler.require(*Rails.groups(assets: %w(development test)))
@@ -39,6 +40,8 @@ class Application < Rails::Application
config.middleware.use Rack::ContentLength
+ config.middleware.use BasicAuthentication
+
config.exceptions_app = self.routes
config.active_record.schema_format = :sql
View
12 lib/basic_authentication.rb
@@ -0,0 +1,12 @@
+class BasicAuthentication
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ if env['HTTP_AUTHORIZATION'].respond_to?(:include?) && !env['HTTP_AUTHORIZATION'].include?('Basic')
+ env['HTTP_AUTHORIZATION'] = "Basic #{env['HTTP_AUTHORIZATION']}"
+ end
+ @app.call(env)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.