11require 'rack/mount'
22require 'rack/auth/basic'
3+ require 'rack/auth/digest/md5'
34require 'logger'
45
56module Grape
@@ -138,7 +139,7 @@ def helpers(&block)
138139 end
139140
140141 # Add an authentication type to the API. Currently
141- # only `:http_basic` is supported.
142+ # only `:http_basic`, `:http_digest` and `:oauth2` are supported.
142143 def auth ( type = nil , options = { } , &block )
143144 if type
144145 set ( :auth , { :type => type . to_sym , :proc => block } . merge ( options ) )
@@ -155,6 +156,12 @@ def http_basic(options = {}, &block)
155156 options [ :realm ] ||= "API Authorization"
156157 auth :http_basic , options , &block
157158 end
159+
160+ def http_digest ( options = { } , &block )
161+ options [ :realm ] ||= "API Authorization"
162+ options [ :opaque ] ||= "secret"
163+ auth :http_digest , options , &block
164+ end
158165
159166 # Defines a route that will be recognized
160167 # by the Grape API.
@@ -257,6 +264,7 @@ def build_endpoint(&block)
257264 :format => settings [ :error_format ] || :txt ,
258265 :rescue_options => settings [ :rescue_options ]
259266 b . use Rack ::Auth ::Basic , settings [ :auth ] [ :realm ] , &settings [ :auth ] [ :proc ] if settings [ :auth ] && settings [ :auth ] [ :type ] == :http_basic
267+ b . use Rack ::Auth ::Digest ::MD5 , settings [ :auth ] [ :realm ] , settings [ :auth ] [ :opaque ] , &settings [ :auth ] [ :proc ] if settings [ :auth ] && settings [ :auth ] [ :type ] == :http_digest
260268 b . use Grape ::Middleware ::Prefixer , :prefix => prefix if prefix
261269 b . use Grape ::Middleware ::Versioner , :versions => ( version if version . is_a? ( Array ) ) if version
262270 b . use Grape ::Middleware ::Formatter , :default_format => default_format || :json
0 commit comments