Class: OpenBEL::JWTMiddleware::Authentication

Inherits:
Object
  • Object
show all
Defined in:
app/openbel/api/middleware/auth.rb

Instance Method Summary collapse

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.check_cookie(env)
    rescue Exception => e
      return _401(e.message)
    end
    @app.call(env)
  end
end