class OmniAuth::Strategies::Ekuaishou

Public Instance Methods

authorize_params() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/ekuaishou.rb, line 15
def authorize_params
  super.tap do |params|
    params[:app_id] = options.client_id if params[:app_id].to_s.strip.empty?

    if params[:scope]
      scope = params[:scope]
      scope = JSON.parse(params[:scope]) && params[:scope] rescue params[:scope].split(',') if scope.is_a?(String)
      params[:scope] = scope.is_a?(Array) ? scope.to_json : scope
    end

    %w[scope client_options].each do |v|
      if request.params[v]
        params[v.to_sym] = request.params[v]
        # to support omniauth-oauth2's auto csrf protection
        session['omniauth.state'] = params[:state] if v == 'state'
      end
    end
  end
end
raw_info() click to toggle source
# File lib/omniauth/strategies/ekuaishou.rb, line 65
def raw_info
  @raw_info ||= begin
    resp = client.request(:get, "#{options.client_options[:site]}/rest/openapi/v1/advertiser/info", headers: headers, body: access_token.to_hash.slice('advertiser_id'))
    JSON.parse(resp.body)['data'] rescue {}
  end
end
scope() click to toggle source
# File lib/omniauth/strategies/ekuaishou.rb, line 72
def scope
  access_token['scope']
end

Protected Instance Methods

build_access_token() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/ekuaishou.rb, line 88
def build_access_token
  request.params['code'] = request.params['auth_code']
  super
end
client() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/ekuaishou.rb, line 78
def client
  _client = super
  _client.define_singleton_method(:request) do |verb, url, opts|
    super(verb, url, opts) do |req|
      req.body = req.body.to_json if req.body.is_a?(Hash)
    end
  end
  _client
end
headers() click to toggle source
# File lib/omniauth/strategies/ekuaishou.rb, line 103
def headers
  result = { 'Content-Type' => 'application/json' }
  result['Access-Token'] = access_token.token if access_token
  result
end
token_params() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/ekuaishou.rb, line 93
def token_params
  super.merge(
    'app_id' => client.id,
    'secret' => client.secret,
    'auth_code' => request.params['auth_code'],
    'parse' => :json,
    'headers' => headers
  )
end