class Grape::Middleware::Auth::Base

Attributes

app[RW]
env[RW]
options[RW]

Public Class Methods

new(app, *options) click to toggle source
# File lib/grape/middleware/auth/base.rb, line 13
def initialize(app, *options)
  @app = app
  @options = options.shift
end

Public Instance Methods

_call(env) click to toggle source
# 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.') unless strategy_info.present?

    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) click to toggle source
# File lib/grape/middleware/auth/base.rb, line 18
def call(env)
  dup._call(env)
end