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.



13
14
15
16
# File 'lib/grape/middleware/auth/base.rb', line 13

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

Instance Attribute Details

#appObject

Returns the value of attribute app.



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

def app
  @app
end

#envObject

Returns the value of attribute env.



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

def env
  @env
end

#optionsObject

Returns the value of attribute options.



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

def options
  @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 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



18
19
20
# File 'lib/grape/middleware/auth/base.rb', line 18

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