Class: Rack::SimpleAuth::HMAC::Middleware
- Inherits:
-
Object
- Object
- Rack::SimpleAuth::HMAC::Middleware
- 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.
Class Method Summary collapse
-
.method_missing(name, *args) ⇒ Object
Throw NoMethodError and give hint if method who was called is Rack::SimpleAuth::Middleware.call.
Instance Method Summary collapse
-
#call(env) ⇒ Object
call Method for Rack Middleware/Application.
-
#initialize(app, &block) {|@config| ... } ⇒ Middleware
constructor
Constructor for Rack Middleware (passing the rack stack).
Constructor Details
#initialize(app, &block) {|@config| ... } ⇒ Middleware
Constructor for Rack Middleware (passing the rack stack)
56 57 58 59 60 |
# File 'lib/rack/simple_auth/hmac/middleware.rb', line 56 def initialize(app, &block) @app, @config = app, Config.new yield @config if block_given? end |
Class Method Details
.method_missing(name, *args) ⇒ Object
Throw NoMethodError and give hint if method who was called is Rack::SimpleAuth::Middleware.call
41 42 43 44 45 46 47 48 |
# File 'lib/rack/simple_auth/hmac/middleware.rb', line 41 def self.method_missing(name, *args) msg = "Did you try to use HMAC Middleware as Rack Application via 'run'?\n" if name.eql?(:call) msg << "method: #{name}\n" msg << "args: #{args.inspect}\n" unless name.eql?(:call) msg << "on: #{self}" fail NoMethodError, msg end |
Instance Method Details
#call(env) ⇒ Object
call Method for Rack Middleware/Application
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rack/simple_auth/hmac/middleware.rb', line 67 def call(env) @request = Rack::Request.new(env) @allowed_messages = if valid_request? @app.call(env) else response = Rack::Response.new('Unauthorized', 401, 'Content-Type' => 'text/html') response.finish end end |