Sha256: 8178a0f47a666384c65e0e881b1ce2066e7cd2ed4de4fd850eda7f4751c58785

Contents?: true

Size: 1.23 KB

Versions: 22

Compression:

Stored size: 1.23 KB

Contents

require 'rack/auth/basic'
require 'active_support/concern'

module Grape
  module Middleware
    module Auth
      module DSL
        extend ActiveSupport::Concern

        module ClassMethods
          # Add an authentication type to the API. Currently
          # only `:http_basic`, `:http_digest` are supported.
          def auth(type = nil, options = {}, &block)
            if type
              namespace_inheritable(:auth, options.reverse_merge(type: type.to_sym, proc: block))
              use Grape::Middleware::Auth::Base, namespace_inheritable(:auth)
            else
              namespace_inheritable(:auth)
            end
          end

          # Add HTTP Basic authorization to the API.
          #
          # @param [Hash] options A hash of options.
          # @option options [String] :realm "API Authorization" The HTTP Basic realm.
          def http_basic(options = {}, &block)
            options[:realm] ||= 'API Authorization'
            auth :http_basic, options, &block
          end

          def http_digest(options = {}, &block)
            options[:realm] ||= 'API Authorization'
            options[:opaque] ||= 'secret'
            auth :http_digest, options, &block
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/lib/grape/middleware/auth/dsl.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/lib/grape/middleware/auth/dsl.rb
grape-1.2.5 lib/grape/middleware/auth/dsl.rb
grape-1.2.4 lib/grape/middleware/auth/dsl.rb
grape-1.2.3 lib/grape/middleware/auth/dsl.rb
grape-1.2.2 lib/grape/middleware/auth/dsl.rb
grape-1.2.1 lib/grape/middleware/auth/dsl.rb
grape-1.2.0 lib/grape/middleware/auth/dsl.rb
grape-1.1.0 lib/grape/middleware/auth/dsl.rb
grape-1.0.3 lib/grape/middleware/auth/dsl.rb
grape-1.0.2 lib/grape/middleware/auth/dsl.rb
grape-1.0.1 lib/grape/middleware/auth/dsl.rb
grape-1.0.0 lib/grape/middleware/auth/dsl.rb
grape-0.19.2 lib/grape/middleware/auth/dsl.rb
grape-0.19.1 lib/grape/middleware/auth/dsl.rb
grape-0.19.0 lib/grape/middleware/auth/dsl.rb
grape-0.18.0 lib/grape/middleware/auth/dsl.rb
grape-0.17.0 lib/grape/middleware/auth/dsl.rb
grape-0.16.2 lib/grape/middleware/auth/dsl.rb
grape-0.16.1 lib/grape/middleware/auth/dsl.rb