Class: Grape::Middleware::Auth::Base
- Defined in:
- lib/grape/middleware/auth/base.rb
Instance Attribute Summary collapse
-
#authenticator ⇒ Object
readonly
Returns the value of attribute authenticator.
Attributes inherited from Base
Instance Method Summary collapse
- #base_request ⇒ Object
- #before ⇒ Object
- #credentials ⇒ Object
-
#initialize(app, options = {}, &authenticator) ⇒ Base
constructor
A new instance of Base.
Methods inherited from Base
#after, #call, #call!, #content_type, #content_type_for, #content_types, #default_options, #mime_types, #response
Constructor Details
#initialize(app, options = {}, &authenticator) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/grape/middleware/auth/base.rb', line 9 def initialize(app, = {}, &authenticator) super(app, ) @authenticator = authenticator end |
Instance Attribute Details
#authenticator ⇒ Object (readonly)
Returns the value of attribute authenticator.
7 8 9 |
# File 'lib/grape/middleware/auth/base.rb', line 7 def authenticator @authenticator end |
Instance Method Details
#base_request ⇒ Object
14 15 16 |
# File 'lib/grape/middleware/auth/base.rb', line 14 def base_request raise NotImplementedError, "You must implement base_request." end |
#before ⇒ Object
22 23 24 25 26 |
# File 'lib/grape/middleware/auth/base.rb', line 22 def before unless authenticator.call(*credentials) throw :error, status: 401, message: "API Authorization Failed." end end |
#credentials ⇒ Object
18 19 20 |
# File 'lib/grape/middleware/auth/base.rb', line 18 def credentials base_request.provided? ? base_request.credentials : [nil, nil] end |