class OmniAuth::Strategies::Traycheckout

Attributes

access_token[RW]

Public Instance Methods

auth_hash() click to toggle source
# File lib/omniauth/strategies/traycheckout.rb, line 60
def auth_hash
  self.credentials
end
authorize_params() click to toggle source
# File lib/omniauth/strategies/traycheckout.rb, line 43
def authorize_params
  { consumer_key: options.consumer_key }
end
callback_phase() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/traycheckout.rb, line 51
def callback_phase
  if request.params["code"].blank?
    fail!('code_blank', CallbackError.new(:code_blank, 'code can not be blank'))
  else
    self.access_token = build_access_token
    super
  end
end
client() click to toggle source
# File lib/omniauth/strategies/traycheckout.rb, line 25
def client
  ::OAuth2::Client.new(options.consumer_key,
                       options.consumer_secret,
                       deep_symbolize(options.client_options))
end
request_phase() click to toggle source
# File lib/omniauth/strategies/traycheckout.rb, line 39
def request_phase
  redirect client.authorize_url(authorize_params)
end
token_params() click to toggle source
# File lib/omniauth/strategies/traycheckout.rb, line 47
def token_params
  options.token_params.merge(options_for("token"))
end

Protected Instance Methods

build_access_token() click to toggle source
# File lib/omniauth/strategies/traycheckout.rb, line 66
def build_access_token
  response = client.request(:post, client.token_url, data_request_access_token)
  access_token_opts = JSON.parse(response.body)['data_response']['authorization']
  ::OAuth2::AccessToken.from_hash(client, { access_token: access_token_opts['access_token'],
                                            expires_at: access_token_opts['access_token_expiration'].to_time,
                                            refresh_token: access_token_opts['refresh_token'],
                                            redirect_uri: callback_url })
end
data_request_access_token() click to toggle source
# File lib/omniauth/strategies/traycheckout.rb, line 75
def data_request_access_token
  opts = {}
  opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
  opts[:body] = { code: request.params["code"],
                  consumer_key: options.consumer_key,
                  consumer_secret: options.consumer_secret,
                  type_response: 'J' }
  opts
end
deep_symbolize(options) click to toggle source
# File lib/omniauth/strategies/traycheckout.rb, line 85
def deep_symbolize(options)
  hash = {}
  options.each do |key, value|
    hash[key.to_sym] = value.is_a?(Hash) ? deep_symbolize(value) : value
  end
  hash
end