Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/omniauth/strategies/freeagent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ 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',
:authorize_url => '/v2/approve_app',
:token_url => '/v2/token_endpoint'
}

option :environment, :live

uid do
raw_info['url'].split('/').last.to_i
end
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/omniauth/strategies/freeagent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down