Class: Vhx::Middleware::OAuth2

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/vhx/middleware/oauth2.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ OAuth2

Returns a new instance of OAuth2.



16
17
18
19
# File 'lib/vhx/middleware/oauth2.rb', line 16

def initialize(app, options={})
  super(app)
  @vhx_client = options[:vhx_client]
end

Instance Method Details

#call(env) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/vhx/middleware/oauth2.rb', line 4

def call(env)
  orig_env = env.dup

  begin
    @app.call(env)
  rescue InvalidTokenError
    @vhx_client.refresh_access_token!
    orig_env[:request_headers].merge!(@vhx_client.configured_headers)
    @app.call(orig_env)
  end
end