Class: Grape::Middleware::Auth::Base
- Inherits:
-
Object
- Object
- Grape::Middleware::Auth::Base
- Defined in:
- lib/grape/middleware/auth/base.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#env ⇒ Object
Returns the value of attribute env.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
- #context ⇒ Object
-
#initialize(app, options = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(app, options = {}) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/grape/middleware/auth/base.rb', line 9 def initialize(app, = {}) @app = app @options = || {} end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
7 8 9 |
# File 'lib/grape/middleware/auth/base.rb', line 7 def app @app end |
#env ⇒ Object
Returns the value of attribute env.
7 8 9 |
# File 'lib/grape/middleware/auth/base.rb', line 7 def env @env end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/grape/middleware/auth/base.rb', line 7 def @options end |
Instance Method Details
#_call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/grape/middleware/auth/base.rb', line 22 def _call(env) self.env = env if .key?(:type) auth_proc = [:proc] auth_proc_context = context strategy_info = Grape::Middleware::Auth::Strategies[[:type]] throw(:error, status: 401, message: 'API Authorization Failed.') unless strategy_info.present? strategy = strategy_info.create(@app, ) do |*args| auth_proc_context.instance_exec(*args, &auth_proc) end strategy.call(env) else app.call(env) end end |
#call(env) ⇒ Object
18 19 20 |
# File 'lib/grape/middleware/auth/base.rb', line 18 def call(env) dup._call(env) end |
#context ⇒ Object
14 15 16 |
# File 'lib/grape/middleware/auth/base.rb', line 14 def context env['api.endpoint'] end |