class MangoPay::AuthorizationToken::Manager

See docs.mangopay.com/api-references/authenticating/

Public Class Methods

get_environment_key_for_token() click to toggle source
# File lib/mangopay/authorization_token.rb, line 33
def get_environment_key_for_token
  cfg = MangoPay.configuration
  key = "#{cfg.root_url}|#{cfg.client_id}|#{cfg.client_apiKey}"
  key = Digest::MD5.hexdigest(key)
  key
end
get_token() click to toggle source
# File lib/mangopay/authorization_token.rb, line 16
def get_token
  token = storage.get
  env_key = get_environment_key_for_token
  if token.nil? || token['timestamp'].nil? || token['timestamp'] <= Time.now || token['environment_key'] != env_key
    token = MangoPay.request(:post, "/#{MangoPay.version_code}/oauth/token", {}, {}, {}, Proc.new do |req|
      cfg = MangoPay.configuration
      req.basic_auth cfg.client_id, cfg.client_apiKey
      req.body = 'grant_type=client_credentials'
      req.add_field('Content-Type', 'application/x-www-form-urlencoded')
    end)
    token['timestamp'] = Time.now + (token['expires_in'].to_i - 10)
    token['environment_key'] = env_key
    storage.store token
  end
  token
end
storage() click to toggle source
# File lib/mangopay/authorization_token.rb, line 8
def storage
  @@storage ||= StaticStorage.new
end
storage=(storage) click to toggle source
# File lib/mangopay/authorization_token.rb, line 12
def storage= (storage)
  @@storage = storage
end