Class: Faraday::OAuth2CachedToken::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday/oauth2_cached_token/provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Provider

Returns a new instance of Provider.



10
11
12
13
# File 'lib/faraday/oauth2_cached_token/provider.rb', line 10

def initialize(options)
  @options = options
  @cache = options[:store] || ActiveSupport::Cache::MemoryStore.new
end

Instance Method Details

#get_fresh_tokenObject



15
16
17
18
19
# File 'lib/faraday/oauth2_cached_token/provider.rb', line 15

def get_fresh_token
  token = Token.from_access_token(oauth2_client.client_credentials.get_token)
  @cache.write(cache_key, token, expires_in: token.expires_in)
  token
end

#get_tokenObject



21
22
23
# File 'lib/faraday/oauth2_cached_token/provider.rb', line 21

def get_token
  @cache.read(cache_key) || get_fresh_token
end