omniauth-square-oauth2 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f19ab92a8efc93e052e61f76c30ae3aa747e5154e0c22ed05c1dd235a76d2999
4
- data.tar.gz: 734bc25d8e398cc8d33b297b837dbafb7c1cffaa91254523cfed7525f89a2c45
3
+ metadata.gz: d364a56610f62d52a8b1666defb4f2d54caff8a644c800c7b28625ff8bdbb8f6
4
+ data.tar.gz: 845420fc652a8948347613893f72d4d92efbe60068b34800860db2d6ced2540d
5
5
  SHA512:
6
- metadata.gz: e5f1b4c48dd0764ff141ead54e59435c026131cd407d6f430e673cad26aa8edf3d2f314d95a8bf10cfa6e9bc4ea898a6de68775981292d414933dc6e818c93e8
7
- data.tar.gz: 913af461084fd09051c011e10d62202eff7d74f6862e6d6e9a16525bb27c4a3568a109d9eef3714dd760e6c56cc94565e08f8c64ee4317b6e763093cf75c45e1
6
+ metadata.gz: e3231e72c96a8e99f5bb2942d6eaf86e5f06755e936c1a93f98d787633c91624614e844aa7f7d1df71287532a03bb13979ce29fe74c98a8f393c55ad08502e29
7
+ data.tar.gz: 53375e4a96d511a8a1dbf95d62c37546d07268d326eb2eda572036804fb348a91abeb70a517b42bbf44b1403460c68e98b7419c4f3412be82c3a89d45694d59e
@@ -24,7 +24,7 @@ jobs:
24
24
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
25
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
26
  # uses: ruby/setup-ruby@v1
27
- uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
27
+ uses: ruby/setup-ruby@v1
28
28
  with:
29
29
  ruby-version: 2.6
30
30
  - name: Install dependencies
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- omniauth-square-oauth2 (0.0.2)
4
+ omniauth-square-oauth2 (0.2.2)
5
5
  omniauth-oauth2 (>= 1.7.3)
6
6
 
7
7
  GEM
@@ -10,25 +10,36 @@ GEM
10
10
  addressable (2.7.0)
11
11
  public_suffix (>= 2.0.2, < 5.0)
12
12
  ast (2.4.1)
13
+ base64 (0.3.0)
14
+ bigdecimal (3.2.2)
13
15
  crack (0.4.4)
14
16
  diff-lcs (1.4.4)
15
17
  docile (1.3.2)
16
- faraday (2.5.2)
17
- faraday-net_http (>= 2.0, < 3.1)
18
- ruby2_keywords (>= 0.0.4)
19
- faraday-net_http (3.0.0)
18
+ faraday (2.13.1)
19
+ faraday-net_http (>= 2.0, < 3.5)
20
+ json
21
+ logger
22
+ faraday-net_http (3.4.1)
23
+ net-http (>= 0.5.0)
20
24
  hashdiff (1.0.1)
21
25
  hashie (5.0.0)
22
- jwt (2.5.0)
23
- multi_xml (0.6.0)
24
- oauth2 (2.0.7)
25
- faraday (>= 0.17.3, < 3.0)
26
- jwt (>= 1.0, < 3.0)
26
+ json (2.12.2)
27
+ jwt (3.1.1)
28
+ base64
29
+ logger (1.7.0)
30
+ multi_xml (0.7.2)
31
+ bigdecimal (~> 3.1)
32
+ net-http (0.6.0)
33
+ uri
34
+ oauth2 (2.0.12)
35
+ faraday (>= 0.17.3, < 4.0)
36
+ jwt (>= 1.0, < 4.0)
37
+ logger (~> 1.2)
27
38
  multi_xml (~> 0.5)
28
- rack (>= 1.2, < 3)
29
- rash_alt (>= 0.4, < 1)
30
- version_gem (~> 1.1)
31
- omniauth (2.1.0)
39
+ rack (>= 1.2, < 4)
40
+ snaky_hash (~> 2.0, >= 2.0.3)
41
+ version_gem (>= 1.1.8, < 3)
42
+ omniauth (2.1.3)
32
43
  hashie (>= 3.4.6)
33
44
  rack (>= 2.2.3)
34
45
  rack-protection
@@ -40,14 +51,12 @@ GEM
40
51
  ast (~> 2.4.1)
41
52
  public_suffix (4.0.6)
42
53
  rack (2.2.3)
43
- rack-protection (2.2.2)
54
+ rack-protection (3.0.6)
44
55
  rack
45
56
  rack-test (1.1.0)
46
57
  rack (>= 1.0, < 3)
47
58
  rainbow (3.0.0)
48
59
  rake (10.5.0)
49
- rash_alt (0.4.12)
50
- hashie (>= 3.4)
51
60
  regexp_parser (1.8.1)
52
61
  rexml (3.2.4)
53
62
  rspec (2.99.0)
@@ -70,13 +79,16 @@ GEM
70
79
  rubocop-ast (0.7.1)
71
80
  parser (>= 2.7.1.5)
72
81
  ruby-progressbar (1.10.1)
73
- ruby2_keywords (0.0.5)
74
82
  simplecov (0.19.0)
75
83
  docile (~> 1.1)
76
84
  simplecov-html (~> 0.11)
77
85
  simplecov-html (0.12.3)
86
+ snaky_hash (2.0.3)
87
+ hashie (>= 0.1.0, < 6)
88
+ version_gem (>= 1.1.8, < 3)
78
89
  unicode-display_width (1.7.0)
79
- version_gem (1.1.0)
90
+ uri (1.0.3)
91
+ version_gem (1.1.8)
80
92
  webmock (3.9.1)
81
93
  addressable (>= 2.3.6)
82
94
  crack (>= 0.3.2)
data/README.md CHANGED
@@ -8,7 +8,7 @@ Square uses the OAuth2 flow, you can read about it here: http://connect.squareup
8
8
 
9
9
  So let's say you're using Rails, you need to add the strategy to your `Gemfile`:
10
10
 
11
- gem 'omniauth-square-oauth2', '~> 1.0.0'
11
+ gem 'omniauth-square-oauth2', '~> 0.2.2'
12
12
 
13
13
  You can pull it in directly from github (if you really want to) e.g.:
14
14
 
@@ -20,7 +20,15 @@ Once these are in, you need to add the following to your `config/initializers/de
20
20
 
21
21
  Sandbox Example:
22
22
 
23
- config.omniauth :square, "your_app_id", "your_app_oauth_secret", {:scope => "ITEMS_READ,ITEMS_WRITE,MERCHANT_PROFILE_READ", :client_options => {:connect_site => 'https://connect.squareupsandbox.com', :site => 'https://squareupsandbox.com'}}
23
+ config.omniauth :square, "your_app_id", "your_app_oauth_secret", {:scope => "ITEMS_READ,ITEMS_WRITE,MERCHANT_PROFILE_READ", :client_options => {:site => 'https://connect.squareupsandbox.com'}}
24
+
25
+ ## Configuration Options
26
+
27
+ ### Session Parameter
28
+
29
+ To prevent repeated authorization prompts for already-authorized applications, you can set `session: false`:
30
+
31
+ config.omniauth :square, "your_app_id", "your_app_oauth_secret", {:scope => "ITEMS_READ,ITEMS_WRITE,MERCHANT_PROFILE_READ", :session => false}
24
32
 
25
33
  You will obviously have to put in your key and secret, which you get when you register your app with Square (they call them Application Key and Secret Key).
26
34
 
@@ -30,6 +30,12 @@ module OmniAuth
30
30
  full_host + script_name + callback_path
31
31
  end
32
32
 
33
+ def authorize_params
34
+ super.tap do |params|
35
+ params[:session] = options[:session] if options[:session] == false
36
+ end
37
+ end
38
+
33
39
  def build_access_token
34
40
  options.token_params.merge!({client_id: options.client_id, client_secret: options.client_secret})
35
41
  super
@@ -41,8 +47,10 @@ module OmniAuth
41
47
  @raw_info ||= access_token.get('/v2/merchants').parsed
42
48
 
43
49
  # Get merchant email
44
- team_members = access_token.post("/v2/team-members/search", {query: {filter: {is_owner: true}}})
45
- @raw_info.merge!({email: team_members[0].email})
50
+ log :info, "Getting merchant email"
51
+ resp = access_token.post("/v2/team-members/search", {query: {filter: {is_owner: true}}}).parsed
52
+ log :info, "Got merchant email: #{resp[:team_members][0]}"
53
+ @raw_info.merge!({email: resp[:team_members][0].email_address})
46
54
  end
47
55
 
48
56
  def prune!(hash)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Omniauth
4
4
  module Square
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.2'
6
6
  end
7
7
  end
@@ -16,15 +16,15 @@ describe OmniAuth::Strategies::Square do
16
16
 
17
17
  describe '#client' do
18
18
  it 'has correct Square site' do
19
- subject.client.site.should eq('https://squareup.com/')
19
+ subject.client.site.should eq('https://connect.squareup.com')
20
20
  end
21
21
 
22
22
  it 'has correct authorize url' do
23
- subject.client.options[:authorize_url].should eq('/oauth2/authorize')
23
+ subject.client.options[:authorize_url].should eq('oauth2/authorize')
24
24
  end
25
25
 
26
26
  it 'has correct token url' do
27
- subject.client.options[:token_url].should eq('/oauth2/token')
27
+ subject.client.options[:token_url].should eq('oauth2/token')
28
28
  end
29
29
  end
30
30
 
@@ -106,4 +106,32 @@ describe OmniAuth::Strategies::Square do
106
106
  subject.credentials.should_not have_key('refresh_token')
107
107
  end
108
108
  end
109
+
110
+ describe '#authorize_params' do
111
+ context 'when session is set to false' do
112
+ before do
113
+ @options = { session: false }
114
+ end
115
+
116
+ it 'includes session=false in authorize params' do
117
+ subject.authorize_params[:session].should eq(false)
118
+ end
119
+ end
120
+
121
+ context 'when session is not set' do
122
+ it 'does not include session in authorize params' do
123
+ subject.authorize_params.should_not have_key(:session)
124
+ end
125
+ end
126
+
127
+ context 'when session is set to true' do
128
+ before do
129
+ @options = { session: true }
130
+ end
131
+
132
+ it 'does not include session in authorize params' do
133
+ subject.authorize_params.should_not have_key(:session)
134
+ end
135
+ end
136
+ end
109
137
  end
data/test_session.rb ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'omniauth/strategies/square'
4
+
5
+ # Mock the necessary environment
6
+ class MockApp
7
+ def call(env)
8
+ [200, {}, ['Hello World']]
9
+ end
10
+ end
11
+
12
+ class MockRequest
13
+ def initialize
14
+ @env = {
15
+ 'rack.session' => {},
16
+ 'REQUEST_METHOD' => 'GET',
17
+ 'PATH_INFO' => '/auth/square',
18
+ 'rack.url_scheme' => 'http',
19
+ 'HTTP_HOST' => 'localhost:3000'
20
+ }
21
+ end
22
+
23
+ def env
24
+ @env
25
+ end
26
+
27
+ def params
28
+ {}
29
+ end
30
+
31
+ def scheme
32
+ 'http'
33
+ end
34
+
35
+ def url
36
+ 'http://localhost:3000/auth/square'
37
+ end
38
+ end
39
+
40
+ # Test without session parameter
41
+ puts "Testing without session parameter:"
42
+ strategy = OmniAuth::Strategies::Square.new(MockApp.new)
43
+ request = MockRequest.new
44
+ strategy.instance_variable_set(:@env, request.env)
45
+ params = strategy.authorize_params
46
+ puts "Has session param: #{params.key?(:session)}"
47
+ puts "Session value: #{params[:session]}" if params.key?(:session)
48
+
49
+ # Test with session: false
50
+ puts "\nTesting with session: false:"
51
+ strategy = OmniAuth::Strategies::Square.new(MockApp.new, {session: false})
52
+ request = MockRequest.new
53
+ strategy.instance_variable_set(:@env, request.env)
54
+ params = strategy.authorize_params
55
+ puts "Has session param: #{params.key?(:session)}"
56
+ puts "Session value: #{params[:session]}" if params.key?(:session)
57
+
58
+ # Test with session: true (should not include session param)
59
+ puts "\nTesting with session: true:"
60
+ strategy = OmniAuth::Strategies::Square.new(MockApp.new, {session: true})
61
+ request = MockRequest.new
62
+ strategy.instance_variable_set(:@env, request.env)
63
+ params = strategy.authorize_params
64
+ puts "Has session param: #{params.key?(:session)}"
65
+ puts "Session value: #{params[:session]}" if params.key?(:session)
66
+
67
+ puts "\nAll params for session: false case:"
68
+ strategy = OmniAuth::Strategies::Square.new(MockApp.new, {session: false})
69
+ request = MockRequest.new
70
+ strategy.instance_variable_set(:@env, request.env)
71
+ params = strategy.authorize_params
72
+ puts params.inspect
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-square-oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Robinson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-17 00:00:00.000000000 Z
11
+ date: 2025-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2
@@ -129,6 +129,7 @@ files:
129
129
  - spec/omniauth/strategies/square_spec.rb
130
130
  - spec/spec_helper.rb
131
131
  - spec/support/shared_examples.rb
132
+ - test_session.rb
132
133
  homepage: https://github.com/nickrobinson/omniauth-square-oauth2
133
134
  licenses:
134
135
  - MIT
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  - !ruby/object:Gem::Version
149
150
  version: '0'
150
151
  requirements: []
151
- rubygems_version: 3.1.2
152
+ rubygems_version: 3.4.19
152
153
  signing_key:
153
154
  specification_version: 4
154
155
  summary: Square OAuth strategy for OmniAuth