Class: MAuth::Rack::RequestAuthenticationFaker
- Inherits:
-
RequestAuthenticator
- Object
- Middleware
- RequestAuthenticator
- MAuth::Rack::RequestAuthenticationFaker
- Defined in:
- lib/mauth/fake/rack.rb
Overview
This middleware bypasses actual authentication (it does not invoke mauth_client.authentic?). It instead uses a class attr method (is_authenic?) to determine if the request should be deemed authentic or not. Requests are authentic by default and RequestAuthenticationFaker.authentic = false must be called BEFORE EACH REQUEST in order to make a request inauthentic.
This is for testing environments where you do not wish to rely on a mauth service for making requests.
Note that if your application does not use env or env then it may be simpler to simply omit the request authentication middleware entirely in your test environment (rather than switching to this fake one), as all this does is add those keys to the request env.
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from RequestAuthenticator
#handle_head, #response_for_inauthentic_request, #response_for_missing_v2, #response_for_unable_to_authenticate, #should_authenticate?
Methods inherited from Middleware
Constructor Details
This class inherits a constructor from MAuth::Middleware
Class Method Details
.authentic=(is_auth = true) ⇒ Object
21 22 23 |
# File 'lib/mauth/fake/rack.rb', line 21 def authentic=(is_auth = true) @is_authentic = is_auth end |
.is_authentic? ⇒ Boolean
17 18 19 |
# File 'lib/mauth/fake/rack.rb', line 17 def is_authentic? @is_authentic.nil? ? true : @is_authentic end |
Instance Method Details
#call(env) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mauth/fake/rack.rb', line 26 def call(env) retval = if should_authenticate?(env) mauth_request = MAuth::Rack::Request.new(env) env['mauth.protocol_version'] = mauth_request.protocol_version if self.class.is_authentic? @app.call(env.merge!('mauth.app_uuid' => mauth_request.signature_app_uuid, 'mauth.authentic' => true)) else response_for_inauthentic_request(env) end else @app.call(env) end # ensure that the next request is marked authenic unless the consumer of this middleware explicitly deems otherwise self.class.authentic = true retval end |