shopify_app 13.0.0 → 13.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +28 -0
  3. data/.rubocop.yml +13 -6
  4. data/.travis.yml +4 -3
  5. data/CHANGELOG.md +33 -0
  6. data/Gemfile +5 -0
  7. data/README.md +67 -38
  8. data/Rakefile +1 -0
  9. data/SECURITY.md +59 -0
  10. data/app/controllers/concerns/shopify_app/require_known_shop.rb +39 -0
  11. data/app/controllers/shopify_app/authenticated_controller.rb +1 -0
  12. data/app/controllers/shopify_app/callback_controller.rb +39 -8
  13. data/app/controllers/shopify_app/extension_verification_controller.rb +2 -7
  14. data/app/controllers/shopify_app/sessions_controller.rb +9 -6
  15. data/app/controllers/shopify_app/webhooks_controller.rb +6 -5
  16. data/config/locales/fi.yml +1 -1
  17. data/config/locales/nl.yml +7 -7
  18. data/config/routes.rb +1 -0
  19. data/docs/Quickstart.md +5 -14
  20. data/docs/Releasing.md +1 -0
  21. data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +5 -3
  22. data/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb +1 -0
  23. data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +2 -1
  24. data/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +4 -4
  25. data/lib/generators/shopify_app/add_webhook/add_webhook_generator.rb +5 -4
  26. data/lib/generators/shopify_app/add_webhook/templates/{webhook_job.rb → webhook_job.rb.tt} +5 -0
  27. data/lib/generators/shopify_app/app_proxy_controller/app_proxy_controller_generator.rb +4 -3
  28. data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_controller.rb +3 -3
  29. data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_route.rb +10 -9
  30. data/lib/generators/shopify_app/controllers/controllers_generator.rb +1 -0
  31. data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +4 -3
  32. data/lib/generators/shopify_app/install/install_generator.rb +10 -9
  33. data/lib/generators/shopify_app/install/templates/omniauth.rb +2 -1
  34. data/lib/generators/shopify_app/install/templates/{shopify_app.rb → shopify_app.rb.tt} +1 -1
  35. data/lib/generators/shopify_app/install/templates/user_agent.rb +2 -1
  36. data/lib/generators/shopify_app/routes/routes_generator.rb +1 -0
  37. data/lib/generators/shopify_app/routes/templates/routes.rb +10 -9
  38. data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +12 -7
  39. data/lib/generators/shopify_app/shop_model/templates/shop.rb +1 -0
  40. data/lib/generators/shopify_app/shopify_app_generator.rb +4 -3
  41. data/lib/generators/shopify_app/user_model/templates/user.rb +1 -0
  42. data/lib/generators/shopify_app/user_model/user_model_generator.rb +12 -7
  43. data/lib/generators/shopify_app/views/views_generator.rb +1 -0
  44. data/lib/shopify_app.rb +11 -5
  45. data/lib/shopify_app/configuration.rb +15 -8
  46. data/lib/shopify_app/controller_concerns/app_proxy_verification.rb +3 -3
  47. data/lib/shopify_app/controller_concerns/embedded_app.rb +3 -2
  48. data/lib/shopify_app/controller_concerns/localization.rb +1 -0
  49. data/lib/shopify_app/controller_concerns/login_protection.rb +52 -15
  50. data/lib/shopify_app/controller_concerns/payload_verification.rb +24 -0
  51. data/lib/shopify_app/controller_concerns/webhook_verification.rb +3 -18
  52. data/lib/shopify_app/engine.rb +5 -0
  53. data/lib/shopify_app/jobs/scripttags_manager_job.rb +1 -1
  54. data/lib/shopify_app/jobs/webhooks_manager_job.rb +1 -1
  55. data/lib/shopify_app/managers/scripttags_manager.rb +4 -3
  56. data/lib/shopify_app/managers/webhooks_manager.rb +4 -3
  57. data/lib/shopify_app/middleware/jwt_middleware.rb +42 -0
  58. data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +2 -1
  59. data/lib/shopify_app/session/in_memory_session_store.rb +7 -3
  60. data/lib/shopify_app/session/in_memory_shop_session_store.rb +10 -0
  61. data/lib/shopify_app/session/in_memory_user_session_store.rb +10 -0
  62. data/lib/shopify_app/session/jwt.rb +61 -0
  63. data/lib/shopify_app/session/null_user_session_store.rb +22 -0
  64. data/lib/shopify_app/session/session_repository.rb +13 -16
  65. data/lib/shopify_app/session/session_storage.rb +1 -0
  66. data/lib/shopify_app/session/shop_session_storage.rb +21 -9
  67. data/lib/shopify_app/session/user_session_storage.rb +19 -8
  68. data/lib/shopify_app/test_helpers/all.rb +2 -0
  69. data/lib/shopify_app/test_helpers/webhook_verification_helper.rb +17 -0
  70. data/lib/shopify_app/utils.rb +6 -5
  71. data/lib/shopify_app/version.rb +2 -1
  72. data/package-lock.json +4 -4
  73. data/package.json +1 -1
  74. data/shopify_app.gemspec +12 -7
  75. data/yarn.lock +3 -3
  76. metadata +48 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4e2d37f9112725500d1a9f36fe76b743e8981920eea4838024cafd6a71cb5eb
4
- data.tar.gz: 3c52a0ee9a7f40433ad01b82bda3a0c6d30dd9bb45c319f1d457a0bd13c30fc0
3
+ metadata.gz: 6666c7899ac8e3332bf950ce28d445e2fc40886c811631a4bfb3f1e446c286e0
4
+ data.tar.gz: f85b1b7ed7a77e2430ed955ed0f65bd30b5021d85614da8943332077a999d38e
5
5
  SHA512:
6
- metadata.gz: 19a445a22b25b01f860a84128551234313bc44e7acd1583ec90bc96f59d65a8fac208feb1d5a6899453935dd19458196c5253605d85e3ac346be2fa405a50b4c
7
- data.tar.gz: 526354098526753ade6d30a346ffa75b2280707638b66dba61c89b34a771e72dd4c23cfae8bda319de58a7a373e7c05d233a13a4f2f8325c7754cda1ed58d835
6
+ metadata.gz: 6582a20d5b5340e7259aef06660e0a2673f31cc0b9413d6d8fda0a7c7fa34982f7dc08cd69f78cad2a0d4e322aedddcc6e472ba368ac4066f1215dc5daaacc4d
7
+ data.tar.gz: c9bf293b825e474f3ef73353428309baa0c3536c7781597b58ca083fc03b587e210e05dbbdc398edf235b225a537dd3dd02bb612176625d42743a2ae1978aeec
@@ -0,0 +1,28 @@
1
+ name: RuboCop
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - name: Set up Ruby 2.7
12
+ uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.7
15
+ - name: Cache gems
16
+ uses: actions/cache@v1
17
+ with:
18
+ path: vendor/bundle
19
+ key: ${{ runner.os }}-rubocop-${{ hashFiles('**/Gemfile.lock') }}
20
+ restore-keys: |
21
+ ${{ runner.os }}-rubocop-
22
+ - name: Install gems
23
+ run: |
24
+ bundle config path vendor/bundle
25
+ bundle config set without 'default development test'
26
+ bundle install --jobs 4 --retry 3
27
+ - name: Run RuboCop
28
+ run: bundle exec rubocop --parallel
@@ -1,10 +1,17 @@
1
- inherit_from:
2
- - https://shopify.github.io/ruby-style-guide/rubocop.yml
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
3
 
4
- LineLength:
4
+ AllCops:
5
+ TargetRubyVersion: 2.7
5
6
  Exclude:
6
- - test/**/*
7
+ - 'test/tmp/**/*'
8
+ - 'vendor/bundle/**/*'
7
9
 
8
- Metrics/ClassLength:
10
+ Style/MethodCallWithArgsParentheses:
9
11
  Exclude:
10
- - test/**/*
12
+ - '**/Gemfile'
13
+
14
+ Style/ClassAndModuleChildren:
15
+ Exclude:
16
+ - 'test/**/*'
17
+
@@ -13,9 +13,10 @@ cache:
13
13
  yarn: true
14
14
 
15
15
  rvm:
16
- - 2.4.3
17
- - 2.5.0
18
- - 2.6.2
16
+ - 2.4
17
+ - 2.5
18
+ - 2.6
19
+ - 2.7
19
20
 
20
21
  install:
21
22
  - bundle install
@@ -1,3 +1,36 @@
1
+ 13.3.0
2
+ ------
3
+ * Added Payload Verification module [#992](https://github.com/Shopify/shopify_app/pull/992)
4
+ * Add concern to check for valid shop domains in the unauthenticated controller
5
+
6
+ 13.2.0
7
+ ------
8
+ * Get current shop domain from JWT header
9
+ * Validate that the omniauth data matches the JWT data
10
+ * Persist the token information to the session store
11
+
12
+ 13.1.1
13
+ ------
14
+ * Update browser_sniffer to 1.2.2
15
+
16
+ 13.1.0
17
+ ------
18
+ * Adds the shop URL as a parameter when redirecting after the callback
19
+ * Bump minimum Ruby version to 2.4
20
+ * Bug fixes
21
+
22
+ 13.0.1
23
+ ------
24
+ * Small addition to WebhookJob to return if the shop is nil #952
25
+ * Added Rubocop to the Repo #948
26
+ * Added a WebhookVerification test helper #950
27
+ * Fix for deprecation warning while loading session storage at startup
28
+ * Changes that will allow future JWT authentication
29
+
30
+ 13.0.1
31
+ ------
32
+ * fix for deprecation warning while loading session storage at startup
33
+
1
34
  13.0.0
2
35
  ------
3
36
  + #887 Added concurrent user and shop session support (online/offline)
data/Gemfile CHANGED
@@ -1,6 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  source "https://rubygems.org"
2
3
 
3
4
  # Specify your gem's dependencies in shopify_app.gemspec
4
5
  gemspec
5
6
 
6
7
  gem 'rails-controller-testing', group: :test
8
+
9
+ group :rubocop do
10
+ gem 'rubocop-shopify', require: false
11
+ end
data/README.md CHANGED
@@ -8,7 +8,7 @@ Shopify App
8
8
 
9
9
  Shopify Application Rails engine and generator
10
10
 
11
- #### NOTE : Versions 8.0.0 through 8.2.3 contained a CSRF vulnerability that was addressed in version 8.2.4. Please update to version 8.2.4 if you're using an old version.
11
+ #### NOTE: Versions 8.0.0 through 8.2.3 contained a CSRF vulnerability that was addressed in version 8.2.4. Please update to version 8.2.4 if you're using an old version.
12
12
 
13
13
  Table of Contents
14
14
  -----------------
@@ -25,16 +25,16 @@ Table of Contents
25
25
  - [AppProxyVerification](#appproxyverification)
26
26
  - [Troubleshooting](#troubleshooting)
27
27
  - [Testing an embedded app outside the Shopify admin](#testing-an-embedded-app-outside-the-shopify-admin)
28
- - [Migration to 13.0.0](#migrating-to-13)
28
+ - [Migration to 13.0.0](#migrating-to-1300)
29
29
  - [Questions or problems?](#questions-or-problems-)
30
30
  - [Rails 6 Compatibility](#rails-6-compatibility)
31
31
  - [Upgrading from 8.6 to 9.0.0](#upgrading-from-86-to-900)
32
32
 
33
33
  Introduction
34
34
  -----------
35
- Get started with the [Shopify Admin API](https://help.shopify.com/en/api/getting-started) faster; This gem includes a Rails Engine and generators for writing Rails applications using the Shopify API. The Engine provides a SessionsController and all the required code for authenticating with a shop via Oauth (other authentication methods are not supported).
35
+ Get started with the [Shopify Admin API](https://help.shopify.com/en/api/getting-started) faster; This gem includes a Rails Engine and generators for writing Rails applications using the Shopify API. The Engine provides a SessionsController and all the required code for authenticating with a shop via OAuth (other authentication methods are not supported).
36
36
 
37
- *Note: It's recommended to use this on a new Rails project, so that the generator won't overwrite/delete your files.*
37
+ *Note: It's recommended to use this on a new Rails project so that the generator won't overwrite/delete your files.*
38
38
 
39
39
  Learn how to create and deploy a new Shopify App to Heroku with our [quickstart guide](https://github.com/Shopify/shopify_app/blob/master/docs/Quickstart.md), or dive in in less than 5 minutes with this quickstart video:
40
40
 
@@ -42,7 +42,7 @@ Learn how to create and deploy a new Shopify App to Heroku with our [quickstart
42
42
 
43
43
  Become a Shopify App Developer
44
44
  --------------------------------
45
- To become a Shopify App Developer you'll need a [Shopify Partner account.](http://shopify.com/partners) If you don't have a Shopify Partner account, head to http://shopify.com/partners to create one before you start.
45
+ To become a Shopify App Developer, you'll need a [Shopify Partner account.](http://shopify.com/partners) If you don't have a Shopify Partner account, head to http://shopify.com/partners to create one before you start.
46
46
 
47
47
  Once you have a Partner account, [create a new application in the Partner Dashboard](https://help.shopify.com/en/api/tools/partner-dashboard/your-apps) to get an API key and other API credentials.
48
48
 
@@ -50,7 +50,7 @@ To create an application for development set your new app's `App URL` to the URL
50
50
 
51
51
  Installation
52
52
  ------------
53
- To get started add `shopify_app` to your Gemfile and run `bundle install`:
53
+ To get started, add `shopify_app` to your Gemfile and run `bundle install`:
54
54
 
55
55
  ``` sh
56
56
  # Create a new rails app
@@ -67,7 +67,7 @@ Now we are ready to run any of the [generators](#generators) included with `shop
67
67
 
68
68
  #### Rails Compatibility
69
69
 
70
- The lastest version of shopify_app is compatible with Rails `>= 5`. Use version `<= v7.2.8` if you need to work with Rails 4.
70
+ The latest version of shopify_app is compatible with Rails `>= 5`. Use version `<= v7.2.8` if you need to work with Rails 4.
71
71
 
72
72
 
73
73
  Generators
@@ -94,26 +94,22 @@ SHOPIFY_API_SECRET=your api secret
94
94
 
95
95
  These values can be found on the "App Setup" page in the [Shopify Partners Dashboard][dashboard]. If you are checking your code into a code repository, ensure your `.gitignore` prevents your `.env` file from being checked into any publicly accessible code.
96
96
 
97
- **You will need to load the ENV variables into your enviroment, you can do this with the [dot-env](https://github.com/bkeepers/dotenv) gem or any other method you wish to.**
97
+ **You will need to load the ENV variables into your environment, you can do this with the [dot-env](https://github.com/bkeepers/dotenv) gem or any other method you wish to.**
98
98
 
99
99
  ### Install Generator
100
100
 
101
101
  ```sh
102
- $ rails generate shopify_app:install
103
-
104
- # or optionally with arguments:
105
-
106
102
  $ rails generate shopify_app:install
107
103
  ```
108
104
 
109
- Other options include:
105
+ Options include:
110
106
  * `application_name` - the name of your app, it can be supplied with or without double-quotes if a whitespace is present. (e.g. `--application_name Example App` or `--application_name "Example App"`)
111
- * `scope` - the Oauth access scope required for your app, eg **read_products, write_orders**. *Multiple options* need to be delimited by a comma-space, and can be supplied with or without double-quotes
107
+ * `scope` - the OAuth access scope required for your app, e.g. **read_products, write_orders**. *Multiple options* need to be delimited by a comma-space and can be supplied with or without double-quotes
112
108
  (e.g. `--scope read_products, write_orders, write_products` or `--scope "read_products, write_orders, write_products"`)
113
109
  For more information, refer the [docs](http://docs.shopify.com/api/tutorials/oauth).
114
110
  * `embedded` - the default is to generate an [embedded app](http://docs.shopify.com/embedded-app-sdk), if you want a legacy non-embedded app then set this to false, `--embedded false`
115
111
 
116
- You can update any of these settings later on easily, the arguments are simply for convenience.
112
+ You can update any of these settings later on easily; the arguments are simply for convenience.
117
113
 
118
114
  The generator adds ShopifyApp and the required initializers to the host Rails application.
119
115
 
@@ -126,7 +122,7 @@ After running the `install` generator, you can start your app with `bundle exec
126
122
  $ rails generate shopify_app:home_controller
127
123
  ```
128
124
 
129
- This generator creates an example home controller and view which fetches and displays products using the Shopify API
125
+ This generator creates an example home controller and view which fetches and displays products using the Shopify API.
130
126
 
131
127
 
132
128
  ### App Proxy Controller Generator
@@ -135,7 +131,7 @@ This generator creates an example home controller and view which fetches and dis
135
131
  $ rails generate shopify_app:app_proxy_controller
136
132
  ```
137
133
 
138
- This optional generator, not included with the default generator, creates the app proxy controller to handle proxy requests to the app from your shop storefront, modifies 'config/routes.rb' with a namespace route, and an example view which displays current shop information using the LiquidAPI
134
+ This optional generator, not included with the default generator, creates the app proxy controller to handle proxy requests to the app from your shop storefront, modifies 'config/routes.rb' with a namespace route, and an example view which displays current shop information using the LiquidAPI.
139
135
 
140
136
  ### Marketing Extension Generator
141
137
 
@@ -143,11 +139,11 @@ This optional generator, not included with the default generator, creates the ap
143
139
  $ rails generate shopify_app:add_marketing_activity_extension
144
140
  ```
145
141
 
146
- This will create a controller with the endpoints required to build a [marketing activities extension](https://help.shopify.com/en/api/embedded-apps/app-extensions/shopify-admin/marketing-activities). The extension will be generated with a base url at `/marketing_activities`, which should also be configured in partners.
142
+ This will create a controller with the endpoints required to build a [marketing activities extension](https://help.shopify.com/en/api/embedded-apps/app-extensions/shopify-admin/marketing-activities). The extension will be generated with a base URL at `/marketing_activities`, which should also be configured in partners.
147
143
 
148
144
  ### Controllers, Routes and Views
149
145
 
150
- The last group of generators are for your convenience if you want to start overriding code included as part of the Rails engine. For example by default the engine provides a simple SessionController, if you run the `rails generate shopify_app:controllers` generator then this code gets copied out into your app so you can start adding to it. Routes and views follow the exact same pattern.
146
+ The last group of generators are for your convenience if you want to start overriding code included as part of the Rails engine. For example, by default the engine provides a simple SessionController, if you run the `rails generate shopify_app:controllers` generator then this code gets copied out into your app so you can start adding to it. Routes and views follow the exact same pattern.
151
147
 
152
148
  Mounting the Engine
153
149
  -------------------
@@ -170,7 +166,7 @@ The engine may also be mounted at a nested route, for example:
170
166
  mount ShopifyApp::Engine, at: '/nested'
171
167
  ```
172
168
 
173
- This will create the Shopify engine routes under the specified subpath. You'll also need to make some updates to your `shopify_app.rb` and `omniauth.rb` initializers. First update the shopify_app initializer to include a custom `root_url` e.g.:
169
+ This will create the Shopify engine routes under the specified subpath. You'll also need to make some updates to your `shopify_app.rb` and `omniauth.rb` initializers. First, update the shopify_app initializer to include a custom `root_url` e.g.:
174
170
 
175
171
  ```ruby
176
172
  ShopifyApp.configure do |config|
@@ -216,7 +212,7 @@ Authentication
216
212
 
217
213
  ### Callback
218
214
 
219
- Upon completing the authentication flow Shopify calls the app at the `callback_path` mentioned before. If the app needs to do some extra work it can define and configure the route to a custom callback controller, inheriting from `ShopifyApp::CallbackController` and hook into or override any of the defined helper methods. The default callback controller already provides the following behaviour:
215
+ Upon completing the authentication flow, Shopify calls the app at the `callback_path` mentioned before. If the app needs to do some extra work, it can define and configure the route to a custom callback controller, inheriting from `ShopifyApp::CallbackController` and hook into or override any of the defined helper methods. The default callback controller already provides the following behaviour:
220
216
  * Logging into the shop and resetting the session
221
217
  * [Installing Webhooks](https://github.com/Shopify/shopify_app#webhooksmanager)
222
218
  * [Setting Scripttags](https://github.com/Shopify/shopify_app#scripttagsmanager)
@@ -227,22 +223,22 @@ Upon completing the authentication flow Shopify calls the app at the `callback_p
227
223
 
228
224
  ### ShopifyApp::SessionRepository
229
225
 
230
- `ShopifyApp::SessionRepository` allows you as a developer to define how your sessions are stored and retrieved for shops. The `SessionRepository` is configured in the `config/initializers/shopify_app.rb` file and can be set to any object that implements `self.store(auth_session, *args)` which stores the session and returns a unique identifier and `self.retrieve(id)` which returns a `ShopifyAPI::Session` for the passed id. These methods are already implemented as part of the `ShopifyApp::SessionStorage` concern, but can be overridden for custom implementation.
226
+ `ShopifyApp::SessionRepository` allows you as a developer to define how your sessions are stored and retrieved for shops. The `SessionRepository` is configured in the `config/initializers/shopify_app.rb` file and can be set to any object that implements `self.store(auth_session, *args)` which stores the session and returns a unique identifier and `self.retrieve(id)` which returns a `ShopifyAPI::Session` for the passed id. These methods are already implemented as part of the `ShopifyApp::SessionStorage` concern but can be overridden for custom implementation.
231
227
 
232
228
  #### Shop-based token storage
233
- Storing tokens on the store model means that any user login associated to the store will have equal access levels to whatever the original user granted the app.
229
+ Storing tokens on the store model means that any user login associated with the store will have equal access levels to whatever the original user granted the app.
234
230
  ```sh
235
231
  $ rails generate shopify_app:shop_model
236
232
  ```
237
233
  This will generate a shop model which will be the storage for the tokens necessary for authentication.
238
234
 
239
235
  #### User-based token storage
240
- A more granular control over level of access per user on an app might be necessary, to which the shop-based token strategy is not sufficient. Shopify supports a user-based token storage strategy where a unique token to each user can be managed. Shop tokens must still be maintained if you are running background jobs so that you can make use of them when necessary.
236
+ A more granular control over the level of access per user on an app might be necessary, to which the shop-based token strategy is not sufficient. Shopify supports a user-based token storage strategy where a unique token to each user can be managed. Shop tokens must still be maintained if you are running background jobs so that you can make use of them when necessary.
241
237
  ```sh
242
238
  $ rails generate shopify_app:shop_model
243
239
  $ rails generate shopify_app:user_model
244
240
  ```
245
- This will generate a shop model and user model which will be the storage for the tokens necessary for authentication.
241
+ This will generate a shop model and user model, which will be the storage for the tokens necessary for authentication.
246
242
 
247
243
  The current Shopify user will be stored in the rails session at `session[:shopify_user]`
248
244
 
@@ -276,7 +272,7 @@ For backwards compatibility, the engine still provides a controller called `Shop
276
272
 
277
273
  ### AfterAuthenticate Job
278
274
 
279
- If your app needs to perform specific actions after the user is authenticated successfully (i.e. every time a new session is created), ShopifyApp can queue or run a job of your choosing (note that we already provide support for automatically creating Webhooks and Scripttags). To configure the after authenticate job update your initializer as follows:
275
+ If your app needs to perform specific actions after the user is authenticated successfully (i.e. every time a new session is created), ShopifyApp can queue or run a job of your choosing (note that we already provide support for automatically creating Webhooks and Scripttags). To configure the after authenticate job, update your initializer as follows:
280
276
 
281
277
  ```ruby
282
278
  ShopifyApp.configure do |config|
@@ -324,11 +320,11 @@ ShopifyApp.configure do |config|
324
320
  end
325
321
  ```
326
322
 
327
- When the oauth callback is completed successfully ShopifyApp will queue a background job which will ensure all the specified webhooks exist for that shop. Because this runs on every oauth callback it means your app will always have the webhooks it needs even if the user uninstalls and re-installs the app.
323
+ When the OAuth callback is completed successfully, ShopifyApp will queue a background job which will ensure all the specified webhooks exist for that shop. Because this runs on every OAuth callback, it means your app will always have the webhooks it needs even if the user uninstalls and re-installs the app.
328
324
 
329
- ShopifyApp also provides a WebhooksController that receives webhooks and queues a job based on the received topic. For example if you register the webhook from above then all you need to do is create a job called `CartsUpdateJob`. The job will be queued with 2 params: `shop_domain` and `webhook` (which is the webhook body).
325
+ ShopifyApp also provides a WebhooksController that receives webhooks and queues a job based on the received topic. For example, if you register the webhook from above, then all you need to do is create a job called `CartsUpdateJob`. The job will be queued with 2 params: `shop_domain` and `webhook` (which is the webhook body).
330
326
 
331
- If you would like to namespace your jobs you may set `webhook_jobs_namespace` in the config. For example if your app handles webhooks from other ecommerce applications as well, and you want Shopify cart update webhooks to be processed by a job living in `jobs/shopify/webhooks/carts_update_job.rb` rather than `jobs/carts_update_job.rb`):
327
+ If you would like to namespace your jobs, you may set `webhook_jobs_namespace` in the config. For example, if your app handles webhooks from other ecommerce applications as well, and you want Shopify cart update webhooks to be processed by a job living in `jobs/shopify/webhooks/carts_update_job.rb` rather than `jobs/carts_update_job.rb`):
332
328
 
333
329
  ```ruby
334
330
  ShopifyApp.configure do |config|
@@ -366,9 +362,9 @@ class CustomWebhooksController < ApplicationController
366
362
  end
367
363
  ```
368
364
 
369
- The module skips the `verify_authenticity_token` before_action and adds an action to verify that the webhook came from Shopify. You can now add a post route to your application pointing to the controller and action to accept the webhook data from Shopify.
365
+ The module skips the `verify_authenticity_token` before_action and adds an action to verify that the webhook came from Shopify. You can now add a post route to your application, pointing to the controller and action to accept the webhook data from Shopify.
370
366
 
371
- The WebhooksManager uses ActiveJob, if ActiveJob is not configured then by default Rails will run the jobs inline. However it is highly recommended to configure a proper background processing queue like sidekiq or resque in production.
367
+ The WebhooksManager uses ActiveJob. If ActiveJob is not configured then by default Rails will run the jobs inline. However, it is highly recommended to configure a proper background processing queue like Sidekiq or Resque in production.
372
368
 
373
369
  ShopifyApp can create webhooks for you using the `add_webhook` generator. This will add the new webhook to your config and create the required job class for you.
374
370
 
@@ -376,7 +372,7 @@ ShopifyApp can create webhooks for you using the `add_webhook` generator. This w
376
372
  rails g shopify_app:add_webhook -t carts/update -a https://example.com/webhooks/carts_update
377
373
  ```
378
374
 
379
- where `-t` is the topic and `-a` is the address the webhook should be sent to.
375
+ Where `-t` is the topic and `-a` is the address the webhook should be sent to.
380
376
 
381
377
  ScripttagsManager
382
378
  -----------------
@@ -459,7 +455,7 @@ class ReviewsController < ApplicationController
459
455
  end
460
456
  ```
461
457
 
462
- Create your app proxy url in the [Shopify Partners' Dashboard][dashboard], making sure to point it to `https://your_app_website.com/app_proxy`.
458
+ Create your app proxy URL in the [Shopify Partners' Dashboard][dashboard], making sure to point it to `https://your_app_website.com/app_proxy`.
463
459
  ![Creating an App Proxy](/images/app-proxy-screenshot.png)
464
460
 
465
461
  App Bridge
@@ -472,6 +468,31 @@ Troubleshooting
472
468
 
473
469
  see [TROUBLESHOOTING.md](https://github.com/Shopify/shopify_app/blob/master/docs/Troubleshooting.md)
474
470
 
471
+ Using Test Helpers inside your Application
472
+ -----------------------------------------
473
+
474
+ A test helper that will allow you to test `ShopifyApp::WebhookVerification` in the controller from your app, to use this test, you need to `require` it directly inside your app `test/controllers/webhook_verification_test.rb`.
475
+
476
+ ```ruby
477
+ require 'test_helper'
478
+ require 'action_controller'
479
+ require 'action_controller/base'
480
+ require 'shopify_app/test_helpers/webhook_verification_helper'
481
+ ```
482
+
483
+ Or you can require in your `test/test_helper.rb`.
484
+
485
+ ```ruby
486
+ ENV['RAILS_ENV'] ||= 'test'
487
+ require_relative '../config/environment'
488
+ require 'rails/test_help'
489
+ require 'byebug'
490
+ require 'shopify_app/test_helpers/all'
491
+ ```
492
+
493
+ With `lib/shopify_app/test_helpers/all'` more tests can be added and will only need to be required in once in your library.
494
+
495
+
475
496
  Testing an embedded app outside the Shopify admin
476
497
  -------------------------------------------------
477
498
 
@@ -495,14 +516,22 @@ change to how session stores work. Here are the steps to migrate to 13.x
495
516
  ### Shop Model Changes (normally `app/models/shop.rb`)
496
517
  - *CHANGE* `include ShopifyApp::SessionStorage` to `include ShopifyApp::ShopSessionStorage`
497
518
 
519
+ ### Changes to the @shop_session instance variable (normally in `app/controllers/*.rb`)
520
+ - *CHANGE* if you are using shop sessions, `@shop_session` will need to be changed to `@current_shopify_session`.
521
+
522
+ ### Changes to Rails `session`
523
+ - *CHANGE* `session[:shopify]` is no longer set. Use `session[:user_id]` if your app uses user based tokens, or `session[:shop_id]` if your app uses shop based tokens.
524
+
498
525
  ### Changes to `ShopifyApp::LoginProtection`
499
526
  `ShopifyApp::LoginProtection`
500
527
 
501
- if you are using `ShopifyApp::LoginProtection#shop_session` in your code, it will need to be
528
+ - CHANGE if you are using `ShopifyApp::LoginProtection#shopify_session` in your code, it will need to be
502
529
  changed to `ShopifyApp::LoginProtection#activate_shopify_session`
530
+ - CHANGE if you are using `ShopifyApp::LoginProtection#clear_shop_session` in your code, it will need to be
531
+ changed to `ShopifyApp::LoginProtection#clear_shopify_session`
503
532
 
504
533
  ### Notes
505
- You do not need a user model, a shop session is fine for most applications.
534
+ You do not need a user model; a shop session is fine for most applications.
506
535
 
507
536
  Questions or problems?
508
537
  ----------------------
@@ -540,7 +569,7 @@ Upgrading from 8.6 to 9.0.0
540
569
 
541
570
  ### Configuration change
542
571
 
543
- Add an api version configuration in `config/initializers/shopify_app.rb`
572
+ Add an API version configuration in `config/initializers/shopify_app.rb`
544
573
  Set this to the version you want to run against by default. See [Shopify API docs](https://help.shopify.com/en/api/versioning) for versions available.
545
574
  ```ruby
546
575
  config.api_version = '2019-04'
@@ -548,7 +577,7 @@ config.api_version = '2019-04'
548
577
 
549
578
  ### Session storage change
550
579
 
551
- You will need to add an `api_version` method to you session storage object. The default implementation for this is.
580
+ You will need to add an `api_version` method to your session storage object. The default implementation for this is.
552
581
  ```ruby
553
582
  def api_version
554
583
  ShopifyApp.configuration.api_version
@@ -586,7 +615,7 @@ is changed to
586
615
 
587
616
  ### ShopifyAPI changes
588
617
 
589
- You will need to also follow the ShopifyAPI [upgrade guide](https://github.com/Shopify/shopify_api/blob/master/README.md#-breaking-change-notice-for-version-700-) to ensure your app is ready to work with api versioning.
618
+ You will need to also follow the ShopifyAPI [upgrade guide](https://github.com/Shopify/shopify_api/blob/master/README.md#-breaking-change-notice-for-version-700-) to ensure your app is ready to work with API versioning.
590
619
 
591
620
  [dashboard]:https://partners.shopify.com
592
621
  [app-bridge]:https://help.shopify.com/en/api/embedded-apps/app-bridge
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'bundler/gem_tasks'
2
3
  require 'rake/testtask'
3
4
 
@@ -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)