Class: Rack::SimpleAuth::HMAC::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/simple_auth/hmac/middleware.rb

Overview

Middleware class which represents the interface to the rack api via #call and checks if a request is hmac authorized.

Examples:

Basic Usage

"request_config = {
   'GET' => 'path',
   'POST' => 'params',
   'DELETE' => 'path',
   'PUT' => 'path',
   'PATCH' => 'path'
 }

 use Rack::SimpleAuth::HMAC::Middleware do |options|
   options.tolerance = 1500

   options.secret = 'test_secret'
   options.signature = 'test_signature'

   options.logpath = "#{File.expand_path('..', __FILE__)}/logs"
   options.request_config = request_config

   options.verbose = true
 end

 run Rack::Lobster.new"

Instance Method Summary collapse

Constructor Details

#initialize(app) {|@config| ... } ⇒ Middleware

Constructor for Rack Middleware (passing the rack stack)

Parameters:

  • app (Rack Application)
    next middleware or rack app which gets called

Yields:

  • (@config)

38
39
40
41
42
# File 'lib/rack/simple_auth/hmac/middleware.rb', line 38

def initialize(app)
  @app, @config = app, Config.new

  yield @config if block_given?
end

Instance Method Details

#call(env) ⇒ Object

Rack API Interface Method

Parameters:

  • env (Hash)
    Rack Env Hash which contains headers etc..

49
50
51
52
# File 'lib/rack/simple_auth/hmac/middleware.rb', line 49

def call(env)
  # self.dup.call!(env)
  dup.call!(env)
end

#call!(env) ⇒ Object

call! Method

Parameters:

  • env (Hash)
    Rack Env Hash which contains headers etc..

59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rack/simple_auth/hmac/middleware.rb', line 59

def call!(env)
  env = env.dup
  request = Request.new(env, @config)

  if request.valid?
    @app.call(env)
  else
    response = Response.new('Unauthorized', 401, 'Content-Type' => 'text/html')
    response.finish
  end
end