Sha256: 5319a2dcf65fb74408d217a271078feb8ab5bb2fdd7d796fb1421d167106fb7d

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require 'omniauth-oauth2'
require 'multi_json'

module OmniAuth
  module Strategies
    class Paymium < OmniAuth::Strategies::OAuth2
      option :name, 'paymium'

      option :client_options, {
        :site => 'https://www.paymium.com/',
        :authorize_url => 'https://www.paymium.com/api/oauth/authorize',
        :token_url => 'https://www.paymium.com/api/oauth/token'
      }

      option :access_token_options, {
        :mode => :query
      }

      option :authorize_params, {
        :scope => 'profile postal_code'
      }

      def build_access_token
        token_params = {
          :redirect_uri => callback_url.split('?').first,
          :client_id => client.id,
          :client_secret => client.secret
        }
        verifier = request.params['code']
        client.auth_code.get_token(verifier, token_params)
      end

      uid { raw_info['Profile']['CustomerId'] }

      info do
        {
          'email' => raw_info['Profile']['PrimaryEmail'],
          'name' => raw_info['Profile']['Name']
        }
      end

      extra do
        {
          'postal_code' => raw_info['Profile']['PostalCode']
        }
      end

      def raw_info
        access_token.options[:parse] = :json

        # This way is not working right now, do it the longer way
        # for the time being
        #
        #@raw_info ||= access_token.get('/ap/user/profile').parsed

        url = "/api/v1/user/profile"
        params = {:params => { :access_token => access_token.token}}
        @raw_info ||= access_token.client.request(:get, url, params).parsed
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-paymium-1.0.1 lib/omniauth/strategies/paymium.rb