Sha256: 79f5a82822d933f15c8b9e82754626d70e9107b809034f8edc8b8696210c102d

Contents?: true

Size: 1.23 KB

Versions: 5

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, { type: type.to_sym, proc: block }.merge(options))
              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

5 entries across 5 versions & 1 rubygems

Version Path
grape-0.13.0 lib/grape/middleware/auth/dsl.rb
grape-0.12.0 lib/grape/middleware/auth/dsl.rb
grape-0.11.0 lib/grape/middleware/auth/dsl.rb
grape-0.10.1 lib/grape/middleware/auth/dsl.rb
grape-0.10.0 lib/grape/middleware/auth/dsl.rb