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, **options, &block) ⇒ Object



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

def auth(type = nil, **options, &block)
  return inheritable_setting.auth unless type

  inheritable_setting.auth = { type: type.to_sym, proc: block }.merge!(options)
  use Grape::Middleware::Auth::Base, inheritable_setting.auth
end

#http_basic(**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



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

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