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

Included in:
API::Instance
Defined in:
lib/grape/middleware/auth/dsl.rb

Instance Method Summary collapse

Instance Method Details

#auth(type = nil, *legacy_options, **options, &block) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/grape/middleware/auth/dsl.rb', line 7

def auth(type = nil, *legacy_options, **options, &block)
  namespace_inheritable = inheritable_setting.namespace_inheritable
  return namespace_inheritable[:auth] unless type

  options = merge_legacy_auth_options(:auth, legacy_options, options)
  namespace_inheritable[:auth] = { type: type.to_sym, proc: block }.merge!(options)
  use Grape::Middleware::Auth::Base, namespace_inheritable[:auth]
end

#http_basic(*legacy_options, **options) ⇒ Object

Add HTTP Basic authorization to the API.

Parameters:

  • options (Hash)

    a hash of options

Options Hash (**options):

  • :realm (String)

    “API Authorization” the HTTP Basic realm



20
21
22
23
24
# File 'lib/grape/middleware/auth/dsl.rb', line 20

def http_basic(*legacy_options, **options, &)
  options = merge_legacy_auth_options(:http_basic, legacy_options, options)
  options[:realm] ||= 'API Authorization'
  auth(:http_basic, **options, &)
end

#http_digest(*legacy_options, **options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/grape/middleware/auth/dsl.rb', line 26

def http_digest(*legacy_options, **options, &)
  options = merge_legacy_auth_options(:http_digest, legacy_options, options)
  options[:realm] ||= 'API Authorization'

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

  auth(:http_digest, **options, &)
end