omniauth-shopify-oauth2 2.2.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ce833c2725777b3827b0ab489eade910d3ef1998cd9b9bc16d9ec1f2492f3dd
4
- data.tar.gz: cd0bb274266046f948c6ad3838394fc6392efac50567d488d0e1532e3fc165a1
3
+ metadata.gz: 56ba61ca0360e6355277b3ef8d07e3014af91c6a2f0367029ad85c398d0c4d71
4
+ data.tar.gz: 739537485b2fa781786ec76d7f6ed31a6a926f8985c70c87e8fca3bcfff01c23
5
5
  SHA512:
6
- metadata.gz: 7f5223c3153f3bf188054fa647362575774abe5637bdeee8b8a6512bad3a33f5fa2d8ea4489b1f9174377a525483fbb7b47c2d39d6779c01b30fbe70a3b9b426
7
- data.tar.gz: 844a9b2d387ba187117c2ef9aa7f06e624eb2ff1b4d0a35aa49e94a5d384fdfc86e40343b2ddca49847543b05dd341ce86c06da18b4f973a7d711693080b3de7
6
+ metadata.gz: 4c947f136bedc9f7bdbf70c16f1af70a918f813992ba159f4c9a644c1775d93aa71d0faf67791faac6cd54403723d2a0e89303ed2a900ebee66ec0f32599ee65
7
+ data.tar.gz: 48258842cfac090f993d60e65d9db9067ada0d18b449f36d0313452540680b013e1f10eddda257b0447c7e5e74cb08850024a11c355b3c428cfd90d4eb6c39c5
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ name: Ruby ${{ matrix.version }}
10
+ strategy:
11
+ matrix:
12
+ version: [2.5.0, 2.7.1]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby ${{ matrix.version }}
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.version }}
20
+ bundler-cache: true
21
+ - name: Install dependencies
22
+ run: bundle
23
+ - name: Run Tests
24
+ run: bundle exec rake
25
+
data/Gemfile CHANGED
@@ -2,6 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2")
6
- gem 'rack', '~> 1.6'
5
+ group :development, :test do
6
+ gem 'fakeweb', git: 'https://github.com/chrisk/fakeweb.git'
7
7
  end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://api.travis-ci.org/Shopify/omniauth-shopify-oauth2.png?branch=master)](http://travis-ci.org/Shopify/omniauth-shopify-oauth2)
1
+ [![Build Status](https://github.com/Shopify/omniauth-shopify-oauth2/workflows/CI/badge.svg?branch=master)](https://github.com/Shopify/omniauth-shopify-oauth2/actions)
2
2
 
3
3
  # OmniAuth Shopify
4
4
 
@@ -36,6 +36,35 @@ Authenticate the user by having them visit /auth/shopify with a `shop` query par
36
36
  </form>
37
37
  ```
38
38
 
39
+ Or without form `/auth/shopify?shop=your-shop-url.myshopify.com`
40
+ Alternatively you can put shop parameter to session as [Shopify App](https://github.com/Shopify/shopify_app) do
41
+
42
+ ```ruby
43
+ session['shopify.omniauth_params'] = { shop: params[:shop] }
44
+ ```
45
+
46
+ And finally it's possible to use your own query parameter by overriding default setup method. For example, like below:
47
+
48
+ ```ruby
49
+ Rails.application.config.middleware.use OmniAuth::Builder do
50
+ provider :shopify,
51
+ ENV['SHOPIFY_API_KEY'],
52
+ ENV['SHOPIFY_SHARED_SECRET'],
53
+ option :setup, proc { |env|
54
+ strategy = env['omniauth.strategy']
55
+
56
+
57
+
58
+ site = if strategy.request.params['site']
59
+ "https://#{strategy.request.params['site']}"
60
+ else
61
+ ''
62
+ end
63
+
64
+ env['omniauth.strategy'].options[:client_options][:site] = site
65
+ }
66
+ ```
67
+
39
68
  ## Configuring
40
69
 
41
70
  ### Scope
data/SECURITY.md ADDED
@@ -0,0 +1,59 @@
1
+ # Security Policy
2
+
3
+ ## Supported versions
4
+
5
+ ### New features
6
+
7
+ New features will only be added to the master branch and will not be made available in point releases.
8
+
9
+ ### Bug fixes
10
+
11
+ Only the latest release series will receive bug fixes. When enough bugs are fixed and its deemed worthy to release a new gem, this is the branch it happens from.
12
+
13
+ ### Security issues
14
+
15
+ Only the latest release series will receive patches and new versions in case of a security issue.
16
+
17
+ ### Severe security issues
18
+
19
+ For severe security issues we will provide new versions as above, and also the last major release series will receive patches and new versions. The classification of the security issue is judged by the core team.
20
+
21
+ ### Unsupported Release Series
22
+
23
+ When a release series is no longer supported, it's your own responsibility to deal with bugs and security issues. If you are not comfortable maintaining your own versions, you should upgrade to a supported version.
24
+
25
+ ## Reporting a bug
26
+
27
+ All security bugs in shopify repositories should be reported to [our hackerone program](https://hackerone.com/shopify)
28
+ Shopify's whitehat program is our way to reward security researchers for finding serious security vulnerabilities in the In Scope properties listed at the bottom of this page, including our core application (all functionality associated with a Shopify store, particularly your-store.myshopify.com/admin) and certain ancillary applications.
29
+
30
+ ## Disclosure Policy
31
+
32
+ We look forward to working with all security researchers and strive to be respectful, always assume the best and treat others as peers. We expect the same in return from all participants. To achieve this, our team strives to:
33
+
34
+ - Reply to all reports within one business day and triage within two business days (if applicable)
35
+ - Be as transparent as possible, answering all inquires about our report decisions and adding hackers to duplicate HackerOne reports
36
+ - Award bounties within a week of resolution (excluding extenuating circumstances)
37
+ - Only close reports as N/A when the issue reported is included in Known Issues, Ineligible Vulnerabilities Types or lacks evidence of a vulnerability
38
+
39
+ **The following rules must be followed in order for any rewards to be paid:**
40
+
41
+ - You may only test against shops you have created which include your HackerOne YOURHANDLE @ wearehackerone.com registered email address.
42
+ - You must not attempt to gain access to, or interact with, any shops other than those created by you.
43
+ - The use of commercial scanners is prohibited (e.g., Nessus).
44
+ - Rules for reporting must be followed.
45
+ - Do not disclose any issues publicly before they have been resolved.
46
+ - Shopify reserves the right to modify the rules for this program or deem any submissions invalid at any time. Shopify may cancel the whitehat program without notice at any time.
47
+ - Contacting Shopify Support over chat, email or phone about your HackerOne report is not allowed. We may disqualify you from receiving a reward, or from participating in the program altogether.
48
+ - You are not an employee of Shopify; employees should report bugs to the internal bug bounty program.
49
+ - You hereby represent, warrant and covenant that any content you submit to Shopify is an original work of authorship and that you are legally entitled to grant the rights and privileges conveyed by these terms. You further represent, warrant and covenant that the consent of no other person or entity is or will be necessary for Shopify to use the submitted content.
50
+ - By submitting content to Shopify, you irrevocably waive all moral rights which you may have in the content.
51
+ - All content submitted by you to Shopify under this program is licensed under the MIT License.
52
+ - You must report any discovered vulnerability to Shopify as soon as you have validated the vulnerability.
53
+ - Failure to follow any of the foregoing rules will disqualify you from participating in this program.
54
+
55
+ ** Please see our [Hackerone Profile](https://hackerone.com/shopify) for full details
56
+
57
+ ## Receiving Security Updates
58
+
59
+ To recieve all general updates to vulnerabilities, please subscribe to our hackerone [Hacktivity](https://hackerone.com/shopify/hacktivity)
data/example/config.ru CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'bundler/setup'
2
2
  require 'sinatra/base'
3
+ require 'active_support/core_ext/hash'
3
4
  require 'omniauth-shopify-oauth2'
4
5
 
5
6
  SCOPE = 'read_products,read_orders,read_customers,write_shipping'
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Shopify
3
- VERSION = "2.2.1"
3
+ VERSION = "2.3.2"
4
4
  end
5
5
  end
@@ -26,7 +26,11 @@ module OmniAuth
26
26
  option :setup, proc { |env|
27
27
  strategy = env['omniauth.strategy']
28
28
 
29
- shopify_auth_params = strategy.session['shopify.omniauth_params'] && strategy.session['shopify.omniauth_params'].with_indifferent_access
29
+ shopify_auth_params = strategy.session['shopify.omniauth_params'] ||
30
+ strategy.session['omniauth.params'] ||
31
+ strategy.request.params
32
+
33
+ shopify_auth_params = shopify_auth_params && shopify_auth_params.with_indifferent_access
30
34
  shop = if shopify_auth_params && shopify_auth_params['shop']
31
35
  "https://#{shopify_auth_params['shop']}"
32
36
  else
@@ -78,7 +82,7 @@ module OmniAuth
78
82
 
79
83
  def normalized_scopes(scopes)
80
84
  scope_list = scopes.to_s.split(SCOPE_DELIMITER).map(&:strip).reject(&:empty?).uniq
81
- ignore_scopes = scope_list.map { |scope| scope =~ /\Awrite_(.*)\z/ && "read_#{$1}" }.compact
85
+ ignore_scopes = scope_list.map { |scope| scope =~ /\A(unauthenticated_)?write_(.*)\z/ && "#{$1}read_#{$2}" }.compact
82
86
  scope_list - ignore_scopes
83
87
  end
84
88
 
@@ -94,7 +98,12 @@ module OmniAuth
94
98
  end
95
99
 
96
100
  def valid_permissions?(token)
97
- token && (options[:per_user_permissions] == !token['associated_user'].nil?)
101
+ return false unless token
102
+
103
+ return true if options[:per_user_permissions] && token['associated_user']
104
+ return true if !options[:per_user_permissions] && !token['associated_user']
105
+
106
+ false
98
107
  end
99
108
 
100
109
  def fix_https
@@ -11,16 +11,19 @@ Gem::Specification.new do |s|
11
11
  s.homepage = 'https://github.com/Shopify/omniauth-shopify-oauth2'
12
12
  s.license = 'MIT'
13
13
 
14
+ s.metadata['allowed_push_host'] = 'https://rubygems.org'
15
+
14
16
  s.files = `git ls-files`.split("\n")
15
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
18
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
19
  s.require_paths = ['lib']
18
20
  s.required_ruby_version = '>= 2.1.9'
19
21
 
20
- s.add_runtime_dependency 'omniauth-oauth2', '~> 1.5.0'
22
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.5'
21
23
  s.add_runtime_dependency 'activesupport'
22
24
 
23
25
  s.add_development_dependency 'minitest', '~> 5.6'
26
+ s.add_development_dependency 'rspec', '~> 3.9.0'
24
27
  s.add_development_dependency 'fakeweb', '~> 1.3'
25
28
  s.add_development_dependency 'rake'
26
29
  end
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'omniauth-shopify-oauth2'
3
2
  require 'base64'
4
3
 
@@ -141,4 +140,80 @@ describe OmniAuth::Strategies::Shopify do
141
140
  subject.valid_site?.should eq(true)
142
141
  end
143
142
  end
143
+
144
+ describe '#valid_permissions?' do
145
+ let(:associated_user) do
146
+ {}
147
+ end
148
+
149
+ let(:token) do
150
+ {
151
+ 'associated_user' => associated_user,
152
+ }
153
+ end
154
+
155
+ it 'returns false if there is no token' do
156
+ expect(subject.valid_permissions?(nil)).to be_falsey
157
+ end
158
+
159
+ context 'with per_user_permissions is present' do
160
+ before do
161
+ @options = @options.merge(per_user_permissions: true)
162
+ end
163
+
164
+ context 'when token does not have associated user' do
165
+ let(:associated_user) { nil }
166
+
167
+ it 'return false' do
168
+ expect(subject.valid_permissions?(token)).to be_falsey
169
+ end
170
+ end
171
+
172
+ context 'when token has associated user' do
173
+ it 'return true' do
174
+ expect(subject.valid_permissions?(token)).to be_truthy
175
+ end
176
+ end
177
+ end
178
+
179
+ context 'with per_user_permissions is false' do
180
+ before do
181
+ @options = @options.merge(per_user_permissions: false)
182
+ end
183
+
184
+ context 'when token does not have associated user' do
185
+ let(:associated_user) { nil }
186
+
187
+ it 'return true' do
188
+ expect(subject.valid_permissions?(token)).to be_truthy
189
+ end
190
+ end
191
+
192
+ context 'when token has associated user' do
193
+ it 'return false' do
194
+ expect(subject.valid_permissions?(token)).to be_falsey
195
+ end
196
+ end
197
+ end
198
+
199
+ context 'with per_user_permissions is nil' do
200
+ before do
201
+ @options = @options.merge(per_user_permissions: nil)
202
+ end
203
+
204
+ context 'when token does not have associated user' do
205
+ let(:associated_user) { nil }
206
+
207
+ it 'return true' do
208
+ expect(subject.valid_permissions?(token)).to be_truthy
209
+ end
210
+ end
211
+
212
+ context 'when token has associated user' do
213
+ it 'return false' do
214
+ expect(subject.valid_permissions?(token)).to be_falsey
215
+ end
216
+ end
217
+ end
218
+ end
144
219
  end
@@ -169,8 +169,19 @@ class IntegrationTest < Minitest::Test
169
169
  assert_equal 'https://app.example.com/auth/shopify/callback', redirect_params['redirect_uri']
170
170
  end
171
171
 
172
+ def test_default_setup_reads_shop_from_params
173
+ build_app
174
+
175
+ response = request.get('https://app.example.com/auth/shopify?shop=snowdevil.myshopify.com', opts)
176
+
177
+ assert_equal 302, response.status
178
+ assert_match %r{\A#{Regexp.quote("https://snowdevil.myshopify.com/admin/oauth/authorize?")}}, response.location
179
+ redirect_params = Rack::Utils.parse_query(URI(response.location).query)
180
+ assert_equal 'https://app.example.com/auth/shopify/callback', redirect_params['redirect_uri']
181
+ end
182
+
172
183
  def test_unnecessary_read_scopes_are_removed
173
- build_app scope: 'read_content,read_products,write_products',
184
+ build_app scope: 'read_content,read_products,write_products,unauthenticated_read_checkouts,unauthenticated_write_checkouts',
174
185
  callback_path: '/admin/auth/legacy/callback',
175
186
  myshopify_domain: 'myshopify.dev:3000',
176
187
  setup: lambda { |env|
@@ -181,7 +192,7 @@ class IntegrationTest < Minitest::Test
181
192
  response = request.get("https://app.example.com/auth/shopify?shop=snowdevil.myshopify.dev:3000")
182
193
  assert_equal 302, response.status
183
194
  redirect_params = Rack::Utils.parse_query(URI(response.location).query)
184
- assert_equal 'read_content,write_products', redirect_params['scope']
195
+ assert_equal 'read_content,write_products,unauthenticated_write_checkouts', redirect_params['scope']
185
196
  end
186
197
 
187
198
  def test_callback_with_invalid_state_fails
@@ -255,6 +266,18 @@ class IntegrationTest < Minitest::Test
255
266
  assert_callback_success(response, access_token, code)
256
267
  end
257
268
 
269
+ def test_callback_with_duplicate_read_scopes_works
270
+ build_app scope: 'read_products,write_products,unauthenticated_read_products,unauthenticated_write_products'
271
+
272
+ access_token = SecureRandom.hex(16)
273
+ code = SecureRandom.hex(16)
274
+ expect_access_token_request(access_token, 'write_products,unauthenticated_write_products')
275
+
276
+ response = callback(sign_with_new_secret(shop: 'snowdevil.myshopify.com', code: code, state: opts["rack.session"]["omniauth.state"]))
277
+
278
+ assert_callback_success(response, access_token, code)
279
+ end
280
+
258
281
  def test_callback_with_extra_coma_works
259
282
  build_app scope: 'read_content,,write_products,'
260
283
 
@@ -280,6 +303,18 @@ class IntegrationTest < Minitest::Test
280
303
  assert_equal '/auth/failure?message=invalid_permissions&strategy=shopify', response.location
281
304
  end
282
305
 
306
+ def test_callback_when_per_user_permissions_are_not_present_and_options_is_nil
307
+ build_app(scope: 'scope', per_user_permissions: nil)
308
+
309
+ access_token = SecureRandom.hex(16)
310
+ code = SecureRandom.hex(16)
311
+ expect_access_token_request(access_token, 'scope', nil)
312
+
313
+ response = callback(sign_with_new_secret(shop: 'snowdevil.myshopify.com', code: code, state: opts["rack.session"]["omniauth.state"]))
314
+
315
+ assert_callback_success(response, access_token, code)
316
+ end
317
+
283
318
  def test_callback_when_per_user_permissions_are_not_present_but_requested
284
319
  build_app(scope: 'scope', per_user_permissions: true)
285
320
 
data/test/test_helper.rb CHANGED
@@ -8,4 +8,6 @@ require 'json'
8
8
  require 'active_support/core_ext/hash'
9
9
 
10
10
  OmniAuth.config.logger = Logger.new(nil)
11
+ OmniAuth.config.allowed_request_methods = [:post, :get]
12
+
11
13
  FakeWeb.allow_net_connect = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-shopify-oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Odorcic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-27 00:00:00.000000000 Z
11
+ date: 2021-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.0
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.5.0
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.9.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.9.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: fakeweb
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -88,11 +102,12 @@ extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
104
  - ".github/probots.yml"
105
+ - ".github/workflows/build.yml"
91
106
  - ".gitignore"
92
- - ".travis.yml"
93
107
  - Gemfile
94
108
  - README.md
95
109
  - Rakefile
110
+ - SECURITY.md
96
111
  - example/Gemfile
97
112
  - example/config.ru
98
113
  - lib/omniauth-shopify-oauth2.rb
@@ -107,7 +122,8 @@ files:
107
122
  homepage: https://github.com/Shopify/omniauth-shopify-oauth2
108
123
  licenses:
109
124
  - MIT
110
- metadata: {}
125
+ metadata:
126
+ allowed_push_host: https://rubygems.org
111
127
  post_install_message:
112
128
  rdoc_options: []
113
129
  require_paths:
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.9
4
- - 2.2.2