Skip to content

Commit e1ff61c

Browse files
authored
Merge pull request #104 from XeroAPI/fix_faraday_and_build_inclusion
faraday vsn and dir glob for gem build
2 parents f3f2b0c + 3dc83bb commit e1ff61c

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ creds = {
6161
client_id: ENV['CLIENT_ID'],
6262
client_secret: ENV['CLIENT_SECRET'],
6363
redirect_uri: ENV['REDIRECT_URI'],
64-
scopes: ENV['SCOPES']
64+
scopes: ENV['SCOPES'],
65+
state: "this-can-be-a-custom-state-parameter" # optional
6566
}
6667
xero_client ||= XeroRuby::ApiClient.new(credentials: creds)
6768
```
@@ -86,6 +87,9 @@ In your callback route catch, calling `get_token_set_from_callback` will exchang
8687
token_set = xero_client.get_token_set_from_callback(params)
8788

8889
# save token_set JSON in a datastore in relation to the user authentication
90+
91+
puts params['state']
92+
=> "this-can-be-a-custom-state-parameter"
8993
```
9094

9195
## Making API calls once you have a token_set

lib/xero-ruby/api_client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def initialize(config: Configuration.default, credentials: {})
3434
@client_secret = credentials[:client_secret]
3535
@redirect_uri = credentials[:redirect_uri]
3636
@scopes = credentials[:scopes]
37+
@state = credentials[:state]
3738
@config = config
3839
@user_agent = "xero-ruby-#{VERSION}"
3940
@default_headers = {
@@ -43,7 +44,7 @@ def initialize(config: Configuration.default, credentials: {})
4344
end
4445

4546
def authorization_url
46-
url = "#{@config.login_url}?response_type=code&client_id=#{@client_id}&redirect_uri=#{@redirect_uri}&scope=#{@scopes}"
47+
url = "#{@config.login_url}?response_type=code&client_id=#{@client_id}&redirect_uri=#{@redirect_uri}&scope=#{@scopes}&state=#{@state}"
4748
return url
4849
end
4950

lib/xero-ruby/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
=end
1212

1313
module XeroRuby
14-
VERSION = '2.5.0'
14+
VERSION = '2.5.1'
1515
end

spec/api_client_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe XeroRuby::ApiClient do
44
context 'initialization' do
5-
context 'URL stuff' do
5+
context 'URL config' do
66
context 'host' do
77
it 'removes http from host' do
88
XeroRuby.configure { |c| c.host = 'http://example.com' }
@@ -36,6 +36,20 @@
3636
expect(XeroRuby::Configuration.default.base_path).to eq('')
3737
end
3838
end
39+
40+
context "creates a valid authorization_url" do
41+
it "passes through attributes" do
42+
creds = {
43+
client_id: 'abc',
44+
client_secret: '123',
45+
redirect_uri: 'https://mydomain.com/callback',
46+
scopes: 'openid profile email accounting.transactions accounting.settings',
47+
state: 'i-am-customer-state'
48+
}
49+
api_client = XeroRuby::ApiClient.new(credentials: creds)
50+
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')
51+
end
52+
end
3953
end
4054
end
4155

xero-ruby.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ Gem::Specification.new do |s|
2727
s.license = "Unlicense"
2828
s.required_ruby_version = ">= 2.3"
2929

30-
s.add_runtime_dependency 'faraday', '~> 1.0.1', '>= 1.0.1'
30+
s.add_runtime_dependency 'faraday', '~> 1.0', '>= 1.0.1'
3131
s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
3232
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
3333

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

0 commit comments

Comments
 (0)