Class: Gapic::Rest::FaradayMiddleware::GoogleAuthorization

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/gapic/rest/faraday_middleware.rb

Overview

Request middleware that constructs the Authorization HTTP header using ::Google::Auth::Credentials

Instance Method Summary collapse

Constructor Details

#initialize(app, credentials) ⇒ GoogleAuthorization

Returns a new instance of GoogleAuthorization.

Parameters:

  • app (#call)
  • credentials (::Google::Auth::Credentials)


28
29
30
31
# File 'lib/gapic/rest/faraday_middleware.rb', line 28

def initialize app, credentials
  @credentials = credentials
  super app
end

Instance Method Details

#call(env) ⇒ Object

Parameters:

  • env (Faraday::Env)


34
35
36
37
38
39
# File 'lib/gapic/rest/faraday_middleware.rb', line 34

def call env
  auth_hash = @credentials.client.apply({})
  env.request_headers["Authorization"] = auth_hash[:authorization]

  @app.call env
end