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

Included in:
API
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.



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

def auth(type = nil, options = {}, &block)
  if type
    set(:auth, { type: type.to_sym, proc: block }.merge(options))
    use Grape::Middleware::Auth::Base, settings[:auth]
  else
    settings[: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.



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

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

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



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

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