lib/rails/auth/credentials/injector_middleware.rb in rails-auth-2.1.4 vs lib/rails/auth/credentials/injector_middleware.rb in rails-auth-2.2.0
- old
+ new
@@ -1,18 +1,22 @@
+# frozen_string_literal: true
+
module Rails
module Auth
class Credentials
# A middleware for injecting an arbitrary credentials hash into the Rack environment
# This is intended for development and testing purposes where you would like to
- # simulate a given X.509 certificate being used in a request or user logged in
+ # simulate a given X.509 certificate being used in a request or user logged in.
+ # The credentials argument should either be a hash or a proc that returns one.
class InjectorMiddleware
def initialize(app, credentials)
@app = app
@credentials = credentials
end
def call(env)
- env[Rails::Auth::Env::CREDENTIALS_ENV_KEY] = @credentials
+ credentials = @credentials.respond_to?(:call) ? @credentials.call(env) : @credentials
+ env[Rails::Auth::Env::CREDENTIALS_ENV_KEY] = credentials
@app.call(env)
end
end
end
end