class Faraday::OAuth2CachedToken::Provider

Public Class Methods

new(options) click to toggle source
# File lib/faraday/oauth2_cached_token/provider.rb, line 10
def initialize(options)
  @options = options
  @cache = options[:store] || ActiveSupport::Cache::MemoryStore.new
end

Public Instance Methods

get_fresh_token() click to toggle source
# 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_token() click to toggle source
# File lib/faraday/oauth2_cached_token/provider.rb, line 21
def get_token
  @cache.read(cache_key) || get_fresh_token
end

Private Instance Methods

cache_key() click to toggle source
# File lib/faraday/oauth2_cached_token/provider.rb, line 27
def cache_key
  "oauth2_cached_token_#{@options[:id]}"
end
oauth2_client() click to toggle source
# File lib/faraday/oauth2_cached_token/provider.rb, line 33
def oauth2_client
  OAuth2::Client.new(@options[:id], @options[:secret], @options[:options])
end