Class: JWTSignedRequest::Middlewares::Rack
- Inherits:
-
Object
- Object
- JWTSignedRequest::Middlewares::Rack
- Defined in:
- lib/jwt_signed_request/middlewares/rack.rb
Constant Summary collapse
- UNAUTHORIZED_STATUS_CODE =
401
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app, options = {}) ⇒ Rack
Returns a new instance of Rack.
9 10 11 12 13 14 15 |
# File 'lib/jwt_signed_request/middlewares/rack.rb', line 9 def initialize(app, = {}) @app = app @secret_key = [:secret_key] @algorithm = [:algorithm] @leeway = [:leeway] @exclude_paths = [:exclude_paths] end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jwt_signed_request/middlewares/rack.rb', line 17 def call(env) begin unless excluded_path?(env) args = { request: ::Rack::Request.new(env), secret_key: secret_key, algorithm: algorithm, leeway: leeway }.reject { |_, value| value.nil? } ::JWTSignedRequest.verify(**args) end app.call(env) rescue ::JWTSignedRequest::UnauthorizedRequestError => e [UNAUTHORIZED_STATUS_CODE, {'Content-Type' => 'application/json'} , []] end end |