Class: Faraday::RbacAuthToken
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::RbacAuthToken
- Defined in:
- lib/scooter/middleware/rbac_auth_token.rb
Overview
This middleware checks for tokens and adds them to the request when found. To include this correctly, you will need to pass the dispatcher itself to the initialize method so it can read if the dispatcher has tokens or not. Beyond just the token itself, it also checks the dispatcher if the instance variable send_auth_token_as_query_param is set to true. Otherwise, it will always attach it as an X-Authentication header.
Instance Attribute Summary collapse
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, dispatcher) ⇒ RbacAuthToken
constructor
A new instance of RbacAuthToken.
Constructor Details
#initialize(app, dispatcher) ⇒ RbacAuthToken
Returns a new instance of RbacAuthToken.
17 18 19 20 |
# File 'lib/scooter/middleware/rbac_auth_token.rb', line 17 def initialize(app, dispatcher) super(app) @dispatcher = dispatcher end |
Instance Attribute Details
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
9 10 11 |
# File 'lib/scooter/middleware/rbac_auth_token.rb', line 9 def dispatcher @dispatcher end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/scooter/middleware/rbac_auth_token.rb', line 22 def call(env) if dispatcher.token && dispatcher.send_auth_token_as_query_param query_array = [['token', dispatcher.token]] URI.decode_www_form(env.url.query).each {|tuple| query_array << tuple} if env.url.query env.url.query = URI.encode_www_form(query_array) elsif dispatcher.token env.request_headers['X-Authentication'] = dispatcher.token end @app.call env end |