class OmniAuth::Strategies::PaypalPermissions

Public Instance Methods

callback_url() click to toggle source
# File lib/omniauth/strategies/paypal_permissions.rb, line 34
def callback_url
  full_host + script_name + callback_path
end
raw_info() click to toggle source
# File lib/omniauth/strategies/paypal_permissions.rb, line 58
def raw_info
  @raw_info ||= load_identity()
  @raw_info
end
request_phase() click to toggle source
# File lib/omniauth/strategies/paypal_permissions.rb, line 43
def request_phase
  @request_permissions = @api.build_request_permissions({
      :scope => options.scope,
      :callback => callback_url })
  @response = @api.request_permissions(@request_permissions)

  if @response.success?
    @response.token
    redirect @api.grant_permission_url(@response) # Redirect url to grant permissions
  else
    raise "Error: " + @response.error.inspect
    fail(:invalid_credentials)
  end
end
setup_phase() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/paypal_permissions.rb, line 38
def setup_phase
  @api = ::PayPal::SDK::Permissions::API.new(options.sdk_config.to_h)
  super
end

Private Instance Methods

access_token() click to toggle source
# File lib/omniauth/strategies/paypal_permissions.rb, line 64
def access_token
  if !@access_token
    get_access_token = @api.build_get_access_token({
      :token => request.params["request_token"],
      :verifier => request.params["verification_code"]
    })

    get_access_token_response = @api.get_access_token(get_access_token)
    @access_token = ::PayPal::SDK::Permissions::API.new(options.sdk_config.to_h.merge({
        :token => get_access_token_response.token,
        :token_secret => get_access_token_response.tokenSecret }))

  end
  return @access_token
end
load_identity() click to toggle source
# File lib/omniauth/strategies/paypal_permissions.rb, line 80
def load_identity
  response = access_token.get_basic_personal_data({
      :attributeList => {
        :attribute => [ "http://axschema.org/namePerson/first",
                        "http://axschema.org/namePerson/last",
                        "http://schema.openid.net/contact/fullname",
                        "http://axschema.org/company/name",
                        "http://axschema.org/contact/email",
                        "https://www.paypal.com/webapps/auth/schema/payerID" ] } })
  if response.success?
    identity = {}
    response.response.personalData.each do |datum|
      key = case datum.personalDataKey
            when "https://www.paypal.com/webapps/auth/schema/payerID"
              "uid"
            when "http://axschema.org/namePerson/first"
              "first_name"
            when "http://axschema.org/namePerson/last"
              "last_name"
            when "http://axschema.org/contact/email"
              "email"
            when "http://schema.openid.net/contact/fullname"
              "full_name"
            when "http://axschema.org/company/name"
              "company_name"
            else
              nil
            end
      identity[key] = datum.personalDataValue
    end
    identity["display_name"] = identity["company_name"] || identity["full_name"]
    identity
  else
    fail!(:invalid_credentials)
  end
end
prune!(hash) click to toggle source
# File lib/omniauth/strategies/paypal_permissions.rb, line 117
def prune!(hash)
  hash.delete_if do |_, value|
    prune!(value) if value.is_a?(Hash)
    value.nil? || (value.respond_to?(:empty?) && value.empty?)
  end
end