Class: Utcp::Auth::OAuth2

Inherits:
Base
  • Object
show all
Defined in:
lib/utcp/auth.rb

Instance Method Summary collapse

Methods inherited from Base

#apply_query

Constructor Details

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



55
56
57
58
59
60
61
62
# File 'lib/utcp/auth.rb', line 55

def initialize(token_url:, client_id:, client_secret:, scope: nil)
  @token_url = Utils::Subst.apply(token_url)
  @client_id = Utils::Subst.apply(client_id)
  @client_secret = Utils::Subst.apply(client_secret)
  @scope = scope && Utils::Subst.apply(scope)
  @cached = nil
  @expires_at = Time.at(0)
end

Instance Method Details

#apply_headers(h) ⇒ Object



64
65
66
67
68
# File 'lib/utcp/auth.rb', line 64

def apply_headers(h)
  token = fetch_token
  h["Authorization"] = "Bearer #{token}"
  h
end