Class: Rails::Auth::Credentials::InjectorMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/auth/credentials/injector_middleware.rb

Overview

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. The credentials argument should either be a hash or a proc that returns one.

Instance Method Summary collapse

Constructor Details

#initialize(app, credentials) ⇒ InjectorMiddleware

Returns a new instance of InjectorMiddleware.



11
12
13
14
# File 'lib/rails/auth/credentials/injector_middleware.rb', line 11

def initialize(app, credentials)
  @app = app
  @credentials = credentials
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
# File 'lib/rails/auth/credentials/injector_middleware.rb', line 16

def call(env)
  credentials = @credentials.respond_to?(:call) ? @credentials.call(env) : @credentials
  env[Rails::Auth::Env::CREDENTIALS_ENV_KEY] = credentials
  @app.call(env)
end