Sha256: f6001abcbc5e48fb7f7a0f3661322da4ef0ff09ee87e41d1e815cbf1b6a09100

Contents?: true

Size: 957 Bytes

Versions: 6

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

module Grape
  module Middleware
    module Auth
      class Base
        include Helpers

        attr_accessor :options, :app, :env

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

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

        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
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
grape-2.3.0 lib/grape/middleware/auth/base.rb
grape-2.2.0 lib/grape/middleware/auth/base.rb
grape-2.1.3 lib/grape/middleware/auth/base.rb
grape-2.1.2 lib/grape/middleware/auth/base.rb
grape-2.1.1 lib/grape/middleware/auth/base.rb
grape-2.1.0 lib/grape/middleware/auth/base.rb