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 |
# File 'lib/jwt_signed_request/middlewares/rack.rb', line 9 def initialize(app, = {}) @app = app @secret_key = .fetch(:secret_key) @algorithm = [:algorithm] end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jwt_signed_request/middlewares/rack.rb', line 15 def call(env) begin ::JWTSignedRequest.verify( request: ::Rack::Request.new(env), secret_key: secret_key, algorithm: algorithm ) app.call(env) rescue ::JWTSignedRequest::UnauthorizedRequestError => e [UNAUTHORIZED_STATUS_CODE, {'Content-Type' => 'application/json'} , []] end end |