Skip to content

Commit

Permalink
Merge pull request #104 from XeroAPI/fix_faraday_and_build_inclusion
Browse files Browse the repository at this point in the history
faraday vsn and dir glob for gem build
  • Loading branch information
SerKnight authored Dec 21, 2020
2 parents f3f2b0c + 3dc83bb commit e1ff61c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ creds = {
client_id: ENV['CLIENT_ID'],
client_secret: ENV['CLIENT_SECRET'],
redirect_uri: ENV['REDIRECT_URI'],
scopes: ENV['SCOPES']
scopes: ENV['SCOPES'],
state: "this-can-be-a-custom-state-parameter" # optional
}
xero_client ||= XeroRuby::ApiClient.new(credentials: creds)
```
Expand All @@ -86,6 +87,9 @@ In your callback route catch, calling `get_token_set_from_callback` will exchang
token_set = xero_client.get_token_set_from_callback(params)

# save token_set JSON in a datastore in relation to the user authentication

puts params['state']
=> "this-can-be-a-custom-state-parameter"
```

## Making API calls once you have a token_set
Expand Down
3 changes: 2 additions & 1 deletion lib/xero-ruby/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def initialize(config: Configuration.default, credentials: {})
@client_secret = credentials[:client_secret]
@redirect_uri = credentials[:redirect_uri]
@scopes = credentials[:scopes]
@state = credentials[:state]
@config = config
@user_agent = "xero-ruby-#{VERSION}"
@default_headers = {
Expand All @@ -43,7 +44,7 @@ def initialize(config: Configuration.default, credentials: {})
end

def authorization_url
url = "#{@config.login_url}?response_type=code&client_id=#{@client_id}&redirect_uri=#{@redirect_uri}&scope=#{@scopes}"
url = "#{@config.login_url}?response_type=code&client_id=#{@client_id}&redirect_uri=#{@redirect_uri}&scope=#{@scopes}&state=#{@state}"
return url
end

Expand Down
2 changes: 1 addition & 1 deletion lib/xero-ruby/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
=end

module XeroRuby
VERSION = '2.5.0'
VERSION = '2.5.1'
end
16 changes: 15 additions & 1 deletion spec/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe XeroRuby::ApiClient do
context 'initialization' do
context 'URL stuff' do
context 'URL config' do
context 'host' do
it 'removes http from host' do
XeroRuby.configure { |c| c.host = 'http://example.com' }
Expand Down Expand Up @@ -36,6 +36,20 @@
expect(XeroRuby::Configuration.default.base_path).to eq('')
end
end

context "creates a valid authorization_url" do
it "passes through attributes" do
creds = {
client_id: 'abc',
client_secret: '123',
redirect_uri: 'https://mydomain.com/callback',
scopes: 'openid profile email accounting.transactions accounting.settings',
state: 'i-am-customer-state'
}
api_client = XeroRuby::ApiClient.new(credentials: creds)
expect(api_client.authorization_url).to eq('https://login.xero.com/identity/connect/authorize?response_type=code&client_id=abc&redirect_uri=https://mydomain.com/callback&scope=openid profile email accounting.transactions accounting.settings&state=i-am-customer-state')
end
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions xero-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ Gem::Specification.new do |s|
s.license = "Unlicense"
s.required_ruby_version = ">= 2.3"

s.add_runtime_dependency 'faraday', '~> 1.0.1', '>= 1.0.1'
s.add_runtime_dependency 'faraday', '~> 1.0', '>= 1.0.1'
s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'

s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? }
s.files = Dir.glob("{lib}/**/*") + %w(README.md)
s.test_files = `find spec/*`.split("\n")
s.executables = []
s.require_paths = ["lib"]
Expand Down

0 comments on commit e1ff61c

Please sign in to comment.