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.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Rack API Interface Method.
-
#call!(env) ⇒ Object
call! Method.
-
#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)
39 40 41 42 43 |
# File 'lib/rack/simple_auth/hmac/middleware.rb', line 39 def initialize(app, &block) @app, @config = app, Config.new yield @config if block_given? end |
Instance Method Details
#call(env) ⇒ Object
Rack API Interface Method
50 51 52 |
# File 'lib/rack/simple_auth/hmac/middleware.rb', line 50 def call(env) self.dup.call!(env) end |
#call!(env) ⇒ Object
call! Method
Using ! because this method isn’t a pure function Creating for example @request & @allowed_messages instance variables
Also this is a threadsafe approach for rack
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rack/simple_auth/hmac/middleware.rb', line 64 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 |