Class: OpenBEL::JWTMiddleware::Authentication
- Inherits:
-
Object
- Object
- OpenBEL::JWTMiddleware::Authentication
- Defined in:
- app/openbel/api/middleware/auth.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(app, opts = {}) ⇒ Authentication
Returns a new instance of Authentication.
75 76 77 78 |
# File 'app/openbel/api/middleware/auth.rb', line 75 def initialize(app, opts = {}) @app = app @paths = opts.fetch(:paths, []) end |
Instance Method Details
#call(env) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/openbel/api/middleware/auth.rb', line 80 def call(env) check = false if @paths.size == 0 # w/out paths, always check for token check = true else path = env['PATH_INFO'] # w/ paths, only check for token iff matched if @paths.any? {|x| path.start_with?(x)} check = true end end if check begin JWTMiddleware.(env) rescue Exception => e return _401(e.) end @app.call(env) end end |