Class: Grape::Middleware::Auth::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/grape/middleware/auth/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#context

Constructor Details

#initialize(app, *options) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/grape/middleware/auth/base.rb', line 11

def initialize(app, *options)
  @app = app
  @options = options.shift
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



9
10
11
# File 'lib/grape/middleware/auth/base.rb', line 9

def app
  @app
end

#envObject

Returns the value of attribute env.



9
10
11
# File 'lib/grape/middleware/auth/base.rb', line 9

def env
  @env
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/grape/middleware/auth/base.rb', line 9

def options
  @options
end

Instance Method Details

#_call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/grape/middleware/auth/base.rb', line 20

def _call(env)
  self.env = env

  if options.key?(:type)
    auth_proc = options[:proc]
    auth_proc_context = context

    strategy_info = Grape::Middleware::Auth::Strategies[options[:type]]

    throw(:error, status: 401, message: 'API Authorization Failed.') if strategy_info.blank?

    strategy = strategy_info.create(@app, options) do |*args|
      auth_proc_context.instance_exec(*args, &auth_proc)
    end

    strategy.call(env)

  else
    app.call(env)
  end
end

#call(env) ⇒ Object



16
17
18
# File 'lib/grape/middleware/auth/base.rb', line 16

def call(env)
  dup._call(env)
end