Sha256: 912df5f62104f5003450c08d68432f1a570d968934689e059b91cdfec177e915

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 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 => 'basic'
      }

      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['name'] }

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

      admin_info do
        {
            'email' => admin_info['email'],
            'name' => admin_info['name']
        }
      end


      def raw_info
        access_token.options[:parse] = :json
        @raw_info ||= access_token.get("#{options.client_options.site}/api/v1/user").parsed
      end

      def admin_info
        access_token.options[:parse] = :json
        @admin_info ||= access_token.get("#{options.client_options.site}/api/v1/admin").parsed
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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