Module: Grape::Middleware::Auth::DSL::ClassMethods

Defined in:
lib/grape/middleware/auth/dsl.rb

Instance Method Summary collapse

Instance Method Details

#auth(type = nil, options = {}, &block) ⇒ Object

Add an authentication type to the API. Currently only `:http_basic`, `:http_digest` are supported.


14
15
16
17
18
19
20
21
# File 'lib/grape/middleware/auth/dsl.rb', line 14

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

#http_basic(options = {}, &block) ⇒ Object

Add HTTP Basic authorization to the API.

Parameters:

  • options (Hash) (defaults to: {})

    A hash of options.

Options Hash (options):

  • :realm (String)

    “API Authorization” The HTTP Basic realm.


27
28
29
30
# File 'lib/grape/middleware/auth/dsl.rb', line 27

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

#http_digest(options = {}, &block) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
# File 'lib/grape/middleware/auth/dsl.rb', line 32

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

  if options[:realm].respond_to?(:values_at)
    options[:realm][:opaque] ||= 'secret'
  else
    options[:opaque] ||= 'secret'
  end

  auth :http_digest, options, &block
end