Class: CohesiveMarketplaceMiddleware::AuthMiddleware
- Inherits:
-
Object
- Object
- CohesiveMarketplaceMiddleware::AuthMiddleware
- Defined in:
- lib/cohesive_marketplace_middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ void
constructor
Initializes a new instance of the middleware.
Constructor Details
#initialize(app) ⇒ void
Initializes a new instance of the middleware.
36 37 38 39 |
# File 'lib/cohesive_marketplace_middleware.rb', line 36 def initialize(app) @app = app @ignore_paths = CohesiveMarketplaceMiddleware.collect_ignore_paths end |
Instance Method Details
#call(env) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cohesive_marketplace_middleware.rb', line 41 def call(env) # Check if the current path should be ignored. if !(@ignore_paths.any? { |prefix| env["REQUEST_PATH"] && env["REQUEST_PATH"].start_with?(prefix) }) = env["HTTP_AUTHORIZATION"] if &.start_with?("Bearer ") token = .sub("Bearer ", "") begin env[AUTH_DETAILS_ENV_KEY] = CohesiveMarketplaceSDK.validate_jwt token rescue => exception puts exception return [401, {"Content-Type" => "text/plain"}, [exception.]] end else return [401, {"Content-Type" => "text/plain"}, ["No Token in auth header"]] end end @app.call(env) end |