Class: Tango::Api::Auth::OAuth2

Inherits:
Object
  • Object
show all
Defined in:
lib/tango/api/auth/oauth2.rb

Overview

OAuth2 client credentials flow helper that injects Bearer tokens.

Defined Under Namespace

Classes: Token

Instance Method Summary collapse

Constructor Details

#initialize(token_url:, client_id:, client_secret:, scope: nil, logger: nil) ⇒ OAuth2

Returns a new instance of OAuth2.



15
16
17
18
19
20
21
22
23
# File 'lib/tango/api/auth/oauth2.rb', line 15

def initialize(token_url:, client_id:, client_secret:, scope: nil, logger: nil)
  @token_url = token_url
  @client_id = client_id
  @client_secret = client_secret
  @scope = scope
  @logger = logger || (defined?(Rails) ? Rails.logger : Logger.new($stdout))
  @mutex = Mutex.new
  @token = nil
end

Instance Method Details

#apply(headers) ⇒ Object



25
26
27
28
# File 'lib/tango/api/auth/oauth2.rb', line 25

def apply(headers)
  token = fetch_token
  headers["Authorization"] = "Bearer #{token}"
end