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.
71 72 73 74 |
# File 'app/openbel/api/middleware/auth.rb', line 71 def initialize(app, opts = {}) @app = app @paths = opts.fetch(:paths, []) end |
Instance Method Details
#call(env) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/openbel/api/middleware/auth.rb', line 76 def call(env) check = false if @paths.empty? # w/out paths, always check for token check = true else path = env['PATH_INFO'] # w/ paths, only check for token iff matched check = true if @paths.any? { |x| path.start_with?(x) } end if check begin JWTMiddleware.check_token(env) rescue Exception => e return _401(e.) end @app.call(env) end end |