Sha256: 5d93d0af78713618452392c8287742bed02ae261bc928f34bec74a985f22e93d

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    class SageOne < OmniAuth::Strategies::OAuth2
      option :client_options,
             authorize_url: 'https://www.sageone.com/oauth2/auth/central',
             token_url: 'https://oauth.accounting.sage.com/token'

      option :authorize_params,
             response_type: 'code',
             filter: 'apiv3.1'

      uid do
        access_token['requested_by_id']
      end

      credentials do
        {
          resource_owner_id: access_token['resource_owner_id']
        }
      end

      info do
        {
          country: country
        }
      end

      # Override this method to remove the query string from the callback_url because SageOne
      # requires an exact match
      def callback_url
        super.split('?').first
      end

      protected

      def country
        request.env ? request[:country].try(:downcase) : options.client_options[:country]
      end
    end
  end
end

OmniAuth.config.add_camelization 'sageone', 'SageOne'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
omniauth-sageone-0.6.0 lib/omniauth/strategies/sage_one.rb
omniauth-sageone-0.5.0 lib/omniauth/strategies/sage_one.rb
omniauth-sageone-0.4.0 lib/omniauth/strategies/sage_one.rb