Class: AccessTokenAgent::Connector

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

Constant Summary collapse

FAKE_TOKEN =
'FakeAuthToken'.freeze

Class Attribute Summary collapse

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.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/access_token_agent/connector.rb', line 11

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

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



8
9
10
# File 'lib/access_token_agent/connector.rb', line 8

def instance
  @instance
end

Instance Method Details

#authenticateObject



34
35
36
37
38
# File 'lib/access_token_agent/connector.rb', line 34

def authenticate
  warn "[DEPRECATION] `#{self.class}.authenticate` is deprecated. " \
       'Use `token` instead.'
  token
end

#http_auth_headerObject



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

def http_auth_header
  { 'Authorization' => "Bearer #{token}" }
end

#tokenObject



27
28
29
30
31
32
# File 'lib/access_token_agent/connector.rb', line 27

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

  @known_token.value
end