diff --git a/lib/omniauth/strategies/freeagent.rb b/lib/omniauth/strategies/freeagent.rb index 9234630..3480c29 100644 --- a/lib/omniauth/strategies/freeagent.rb +++ b/lib/omniauth/strategies/freeagent.rb @@ -4,6 +4,8 @@ module OmniAuth module Strategies class FreeAgent < OmniAuth::Strategies::OAuth2 option :name, 'freeagent' + + args [:client_id, :client_secret, :environment] option :client_options, { :site => 'https://api.freeagent.com', @@ -11,6 +13,8 @@ class FreeAgent < OmniAuth::Strategies::OAuth2 :token_url => '/v2/token_endpoint' } + option :environment, :live + uid do raw_info['url'].split('/').last.to_i end @@ -33,6 +37,12 @@ class FreeAgent < OmniAuth::Strategies::OAuth2 def raw_info @raw_info ||= access_token.get('/v2/users/me').parsed['user'] end + + def client + client_options = options.client_options + client_options.merge!(site: 'https://api.sandbox.freeagent.com') if options.environment == :sandbox + ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(client_options)) + end end end end diff --git a/spec/omniauth/strategies/freeagent_spec.rb b/spec/omniauth/strategies/freeagent_spec.rb index b1c1ee4..e322a22 100644 --- a/spec/omniauth/strategies/freeagent_spec.rb +++ b/spec/omniauth/strategies/freeagent_spec.rb @@ -18,6 +18,11 @@ it 'should have the correct token URL' do subject.client.options[:token_url].should == '/v2/token_endpoint' end + + it "in the sandbox environment" do + @options = {environment: :sandbox} + subject.client.site.should == 'https://api.sandbox.freeagent.com' + end end describe '#callback_path' do