Class: AccessTokenAgent::Connector

Inherits:
Object
  • Object
show all
Defined in:
lib/access_token_agent/connector.rb

Constant Summary collapse

FAKE_TOKEN =
'FakeAuthToken'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(host:, client_id:, client_secret:, fake_auth: false, access_token_path: '/oauth/token') ⇒ Connector

Returns a new instance of Connector.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/access_token_agent/connector.rb', line 7

def initialize(host:,
               client_id:,
               client_secret:,
               fake_auth: false,
               access_token_path: '/oauth/token')
  @host = host
  @client_id = client_id
  @client_secret = client_secret
  @fake_auth = fake_auth
  @access_token_path = access_token_path
end

Instance Method Details

#authenticateObject



30
31
32
33
# File 'lib/access_token_agent/connector.rb', line 30

def authenticate
  warn '[DEPRECATION] `authenticate` is deprecated.  Use `token` instead.'
  token
end

#http_auth_headerObject



19
20
21
# File 'lib/access_token_agent/connector.rb', line 19

def http_auth_header
  { Authorization: "Bearer #{token}" }
end

#tokenObject



23
24
25
26
27
28
# File 'lib/access_token_agent/connector.rb', line 23

def token
  return FAKE_TOKEN if @fake_auth
  @known_token = fetch_token unless @known_token && @known_token.valid?

  @known_token.value
end