shopify_app 13.0.0 → 16.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +5 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +6 -0
- data/.github/workflows/build.yml +38 -0
- data/.github/workflows/rubocop.yml +22 -0
- data/.gitignore +0 -2
- data/.rubocop.yml +14 -6
- data/CHANGELOG.md +95 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +252 -0
- data/README.md +83 -45
- data/Rakefile +1 -0
- data/SECURITY.md +59 -0
- data/app/assets/images/storage_access.svg +1 -2
- data/app/assets/javascripts/shopify_app/storage_access.js +2 -1
- data/app/assets/javascripts/shopify_app/top_level_interaction.js +1 -1
- data/app/controllers/concerns/shopify_app/authenticated.rb +1 -0
- data/app/controllers/concerns/shopify_app/require_known_shop.rb +39 -0
- data/app/controllers/shopify_app/authenticated_controller.rb +1 -0
- data/app/controllers/shopify_app/callback_controller.rb +77 -15
- data/app/controllers/shopify_app/extension_verification_controller.rb +2 -7
- data/app/controllers/shopify_app/sessions_controller.rb +24 -7
- data/app/controllers/shopify_app/webhooks_controller.rb +6 -5
- data/app/views/shopify_app/partials/_button_styles.html.erb +41 -36
- data/app/views/shopify_app/partials/_card_styles.html.erb +3 -3
- data/app/views/shopify_app/partials/_empty_state_styles.html.erb +28 -59
- data/app/views/shopify_app/partials/_form_styles.html.erb +56 -0
- data/app/views/shopify_app/partials/_layout_styles.html.erb +16 -1
- data/app/views/shopify_app/partials/_typography_styles.html.erb +6 -6
- data/app/views/shopify_app/sessions/enable_cookies.html.erb +2 -7
- data/app/views/shopify_app/sessions/new.html.erb +38 -110
- data/app/views/shopify_app/sessions/request_storage_access.html.erb +1 -1
- data/app/views/shopify_app/sessions/top_level_interaction.html.erb +21 -22
- data/config/locales/fi.yml +1 -1
- data/config/locales/nl.yml +7 -7
- data/config/locales/th.yml +4 -4
- data/config/routes.rb +1 -0
- data/docs/Quickstart.md +7 -17
- data/docs/Releasing.md +16 -14
- data/karma.conf.js +1 -1
- data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +5 -3
- data/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb +1 -0
- data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +2 -1
- data/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +4 -4
- data/lib/generators/shopify_app/add_webhook/add_webhook_generator.rb +5 -4
- data/lib/generators/shopify_app/add_webhook/templates/{webhook_job.rb → webhook_job.rb.tt} +5 -0
- data/lib/generators/shopify_app/app_proxy_controller/app_proxy_controller_generator.rb +4 -3
- data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_controller.rb +3 -3
- data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_route.rb +10 -9
- data/lib/generators/shopify_app/authenticated_controller/authenticated_controller_generator.rb +1 -1
- data/lib/generators/shopify_app/controllers/controllers_generator.rb +2 -1
- data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +22 -3
- data/lib/generators/shopify_app/home_controller/templates/index.html.erb +67 -17
- data/lib/generators/shopify_app/home_controller/templates/unauthenticated_home_controller.rb +10 -0
- data/lib/generators/shopify_app/install/install_generator.rb +11 -10
- data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +1 -1
- data/lib/generators/shopify_app/install/templates/flash_messages.js +0 -2
- data/lib/generators/shopify_app/install/templates/omniauth.rb +2 -1
- data/lib/generators/shopify_app/install/templates/{shopify_app.rb → shopify_app.rb.tt} +4 -3
- data/lib/generators/shopify_app/install/templates/user_agent.rb +2 -1
- data/lib/generators/shopify_app/products_controller/products_controller_generator.rb +19 -0
- data/lib/generators/shopify_app/products_controller/templates/products_controller.rb +8 -0
- data/lib/generators/shopify_app/routes/routes_generator.rb +1 -0
- data/lib/generators/shopify_app/routes/templates/routes.rb +10 -9
- data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +12 -7
- data/lib/generators/shopify_app/shop_model/templates/shop.rb +1 -0
- data/lib/generators/shopify_app/shopify_app_generator.rb +4 -3
- data/lib/generators/shopify_app/user_model/templates/user.rb +1 -0
- data/lib/generators/shopify_app/user_model/user_model_generator.rb +12 -7
- data/lib/generators/shopify_app/views/views_generator.rb +2 -1
- data/lib/shopify_app/configuration.rb +15 -8
- data/lib/shopify_app/controller_concerns/app_proxy_verification.rb +3 -3
- data/lib/shopify_app/controller_concerns/csrf_protection.rb +15 -0
- data/lib/shopify_app/controller_concerns/embedded_app.rb +3 -2
- data/lib/shopify_app/controller_concerns/itp.rb +2 -0
- data/lib/shopify_app/controller_concerns/localization.rb +1 -0
- data/lib/shopify_app/controller_concerns/login_protection.rb +85 -17
- data/lib/shopify_app/controller_concerns/payload_verification.rb +24 -0
- data/lib/shopify_app/controller_concerns/webhook_verification.rb +3 -18
- data/lib/shopify_app/engine.rb +26 -0
- data/lib/shopify_app/jobs/scripttags_manager_job.rb +1 -1
- data/lib/shopify_app/jobs/webhooks_manager_job.rb +1 -1
- data/lib/shopify_app/managers/scripttags_manager.rb +4 -3
- data/lib/shopify_app/managers/webhooks_manager.rb +4 -3
- data/lib/shopify_app/middleware/jwt_middleware.rb +42 -0
- data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +2 -1
- data/lib/shopify_app/session/in_memory_session_store.rb +7 -3
- data/lib/shopify_app/session/in_memory_shop_session_store.rb +10 -0
- data/lib/shopify_app/session/in_memory_user_session_store.rb +10 -0
- data/lib/shopify_app/session/jwt.rb +63 -0
- data/lib/shopify_app/session/null_user_session_store.rb +22 -0
- data/lib/shopify_app/session/session_repository.rb +13 -16
- data/lib/shopify_app/session/session_storage.rb +1 -0
- data/lib/shopify_app/session/shop_session_storage.rb +21 -9
- data/lib/shopify_app/session/user_session_storage.rb +19 -8
- data/lib/shopify_app/test_helpers/all.rb +2 -0
- data/lib/shopify_app/test_helpers/webhook_verification_helper.rb +17 -0
- data/lib/shopify_app/utils.rb +6 -5
- data/lib/shopify_app/version.rb +2 -1
- data/lib/shopify_app.rb +12 -5
- data/package.json +7 -8
- data/shopify_app.gemspec +12 -7
- data/yarn.lock +2098 -2115
- metadata +56 -12
- data/.travis.yml +0 -27
- data/package-lock.json +0 -7245
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Shopify App
|
2
2
|
===========
|
3
|
-
[![Version][gem]][gem_url] [![Build Status](https://
|
3
|
+
[![Version][gem]][gem_url] [![Build Status](https://github.com/Shopify/shopify_app/workflows/CI/badge.svg)](https://github.com/Shopify/shopify_app/actions?query=workflow%3ACI)
|
4
4
|
|
5
5
|
[gem]: https://img.shields.io/gem/v/shopify_app.svg
|
6
6
|
[gem_url]: https://rubygems.org/gems/shopify_app
|
@@ -8,7 +8,7 @@ Shopify App
|
|
8
8
|
|
9
9
|
Shopify Application Rails engine and generator
|
10
10
|
|
11
|
-
#### NOTE
|
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-
|
29
|
-
- [Questions or problems?](#questions-or-problems
|
28
|
+
- [Migration to 13.0.0](#migrating-to-1300)
|
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
|
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
|
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
|
@@ -58,8 +58,7 @@ $ rails new my_shopify_app
|
|
58
58
|
$ cd my_shopify_app
|
59
59
|
|
60
60
|
# Add the gem shopify_app to your Gemfile
|
61
|
-
$
|
62
|
-
$ bundle install
|
61
|
+
$ bundle add shopify_app
|
63
62
|
```
|
64
63
|
|
65
64
|
Now we are ready to run any of the [generators](#generators) included with `shopify_app`. The following section explains the generators and what you can do with them.
|
@@ -67,7 +66,7 @@ Now we are ready to run any of the [generators](#generators) included with `shop
|
|
67
66
|
|
68
67
|
#### Rails Compatibility
|
69
68
|
|
70
|
-
The
|
69
|
+
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
70
|
|
72
71
|
|
73
72
|
Generators
|
@@ -75,7 +74,7 @@ Generators
|
|
75
74
|
|
76
75
|
### Default Generator
|
77
76
|
|
78
|
-
The default generator will run the `install`, `shop`, and `home_controller` generators. This is the recommended way to start a new app from scratch:
|
77
|
+
The default generator will run the `install`, `shop`, `authenticated_controller`, and `home_controller` generators. This is the recommended way to start a new app from scratch:
|
79
78
|
|
80
79
|
```sh
|
81
80
|
$ rails generate shopify_app
|
@@ -94,26 +93,22 @@ SHOPIFY_API_SECRET=your api secret
|
|
94
93
|
|
95
94
|
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
95
|
|
97
|
-
**You will need to load the ENV variables into your
|
96
|
+
**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
97
|
|
99
98
|
### Install Generator
|
100
99
|
|
101
100
|
```sh
|
102
|
-
$ rails generate shopify_app:install
|
103
|
-
|
104
|
-
# or optionally with arguments:
|
105
|
-
|
106
101
|
$ rails generate shopify_app:install
|
107
102
|
```
|
108
103
|
|
109
|
-
|
104
|
+
Options include:
|
110
105
|
* `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
|
106
|
+
* `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
107
|
(e.g. `--scope read_products, write_orders, write_products` or `--scope "read_products, write_orders, write_products"`)
|
113
|
-
For more information, refer the [docs](http://docs.shopify.com/api/tutorials/oauth).
|
108
|
+
For more information, refer to the [docs](http://docs.shopify.com/api/tutorials/oauth).
|
114
109
|
* `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
110
|
|
116
|
-
You can update any of these settings later on easily
|
111
|
+
You can update any of these settings later on easily; the arguments are simply for convenience.
|
117
112
|
|
118
113
|
The generator adds ShopifyApp and the required initializers to the host Rails application.
|
119
114
|
|
@@ -126,8 +121,18 @@ After running the `install` generator, you can start your app with `bundle exec
|
|
126
121
|
$ rails generate shopify_app:home_controller
|
127
122
|
```
|
128
123
|
|
129
|
-
This generator creates an example home controller and view which fetches and displays products using the Shopify API
|
124
|
+
This generator creates an example home controller and view which fetches and displays products using the Shopify API.
|
130
125
|
|
126
|
+
Options include:
|
127
|
+
* __[beta]__ `with-session-token`: This flag generates an unauthenticated home_controller and a protected sample products_controller. It also creates a home view that leverages a session token to fetch products from your products_controller. Use this flag if you plan to build a single-page application or to secure your app using JWT session tokens (e.g. `--with-session-token` or `--with-session-token true`).
|
128
|
+
|
129
|
+
### Products Controller Generator
|
130
|
+
|
131
|
+
```sh
|
132
|
+
$ rails generate shopify_app:products_controller
|
133
|
+
```
|
134
|
+
|
135
|
+
This generator creates an example products API controller to fetch products using the Shopify API.
|
131
136
|
|
132
137
|
### App Proxy Controller Generator
|
133
138
|
|
@@ -135,7 +140,7 @@ This generator creates an example home controller and view which fetches and dis
|
|
135
140
|
$ rails generate shopify_app:app_proxy_controller
|
136
141
|
```
|
137
142
|
|
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
|
143
|
+
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
144
|
|
140
145
|
### Marketing Extension Generator
|
141
146
|
|
@@ -143,11 +148,11 @@ This optional generator, not included with the default generator, creates the ap
|
|
143
148
|
$ rails generate shopify_app:add_marketing_activity_extension
|
144
149
|
```
|
145
150
|
|
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
|
151
|
+
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
152
|
|
148
153
|
### Controllers, Routes and Views
|
149
154
|
|
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.
|
155
|
+
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
156
|
|
152
157
|
Mounting the Engine
|
153
158
|
-------------------
|
@@ -170,7 +175,7 @@ The engine may also be mounted at a nested route, for example:
|
|
170
175
|
mount ShopifyApp::Engine, at: '/nested'
|
171
176
|
```
|
172
177
|
|
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.:
|
178
|
+
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
179
|
|
175
180
|
```ruby
|
176
181
|
ShopifyApp.configure do |config|
|
@@ -216,7 +221,7 @@ Authentication
|
|
216
221
|
|
217
222
|
### Callback
|
218
223
|
|
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:
|
224
|
+
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
225
|
* Logging into the shop and resetting the session
|
221
226
|
* [Installing Webhooks](https://github.com/Shopify/shopify_app#webhooksmanager)
|
222
227
|
* [Setting Scripttags](https://github.com/Shopify/shopify_app#scripttagsmanager)
|
@@ -227,22 +232,22 @@ Upon completing the authentication flow Shopify calls the app at the `callback_p
|
|
227
232
|
|
228
233
|
### ShopifyApp::SessionRepository
|
229
234
|
|
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
|
235
|
+
`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
236
|
|
232
237
|
#### Shop-based token storage
|
233
|
-
Storing tokens on the store model means that any user login associated
|
238
|
+
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
239
|
```sh
|
235
240
|
$ rails generate shopify_app:shop_model
|
236
241
|
```
|
237
242
|
This will generate a shop model which will be the storage for the tokens necessary for authentication.
|
238
243
|
|
239
244
|
#### 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.
|
245
|
+
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
246
|
```sh
|
242
247
|
$ rails generate shopify_app:shop_model
|
243
248
|
$ rails generate shopify_app:user_model
|
244
249
|
```
|
245
|
-
This will generate a shop model and user model which will be the storage for the tokens necessary for authentication.
|
250
|
+
This will generate a shop model and user model, which will be the storage for the tokens necessary for authentication.
|
246
251
|
|
247
252
|
The current Shopify user will be stored in the rails session at `session[:shopify_user]`
|
248
253
|
|
@@ -276,7 +281,7 @@ For backwards compatibility, the engine still provides a controller called `Shop
|
|
276
281
|
|
277
282
|
### AfterAuthenticate Job
|
278
283
|
|
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:
|
284
|
+
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
285
|
|
281
286
|
```ruby
|
282
287
|
ShopifyApp.configure do |config|
|
@@ -324,11 +329,11 @@ ShopifyApp.configure do |config|
|
|
324
329
|
end
|
325
330
|
```
|
326
331
|
|
327
|
-
When the
|
332
|
+
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
333
|
|
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).
|
334
|
+
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
335
|
|
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`):
|
336
|
+
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
337
|
|
333
338
|
```ruby
|
334
339
|
ShopifyApp.configure do |config|
|
@@ -366,9 +371,9 @@ class CustomWebhooksController < ApplicationController
|
|
366
371
|
end
|
367
372
|
```
|
368
373
|
|
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.
|
374
|
+
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
375
|
|
371
|
-
The WebhooksManager uses ActiveJob
|
376
|
+
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
377
|
|
373
378
|
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
379
|
|
@@ -376,7 +381,7 @@ ShopifyApp can create webhooks for you using the `add_webhook` generator. This w
|
|
376
381
|
rails g shopify_app:add_webhook -t carts/update -a https://example.com/webhooks/carts_update
|
377
382
|
```
|
378
383
|
|
379
|
-
|
384
|
+
Where `-t` is the topic and `-a` is the address the webhook should be sent to.
|
380
385
|
|
381
386
|
ScripttagsManager
|
382
387
|
-----------------
|
@@ -422,7 +427,7 @@ bin/rails g shopify_app:rotate_shopify_token_job
|
|
422
427
|
|
423
428
|
The generated rake task will be found at `lib/tasks/shopify/rotate_shopify_token.rake` and is provided strictly for example purposes. It might not work with your application out of the box without some configuration.
|
424
429
|
|
425
|
-
⚠️ Note: if you are updating `shopify_app` from a version prior to 8.4.2 (and do not wish to run the default/install generator again), you will need to add [the following line](https://github.com/Shopify/shopify_app/blob/4f7e6cca2a472d8f7af44b938bd0fcafe4d8e88a/lib/generators/shopify_app/install/templates/shopify_provider.rb#L18) to `config/
|
430
|
+
⚠️ Note: if you are updating `shopify_app` from a version prior to 8.4.2 (and do not wish to run the default/install generator again), you will need to add [the following line](https://github.com/Shopify/shopify_app/blob/4f7e6cca2a472d8f7af44b938bd0fcafe4d8e88a/lib/generators/shopify_app/install/templates/shopify_provider.rb#L18) to `config/initializers/omniauth.rb`:
|
426
431
|
|
427
432
|
```ruby
|
428
433
|
strategy.options[:old_client_secret] = ShopifyApp.configuration.old_secret
|
@@ -459,7 +464,7 @@ class ReviewsController < ApplicationController
|
|
459
464
|
end
|
460
465
|
```
|
461
466
|
|
462
|
-
Create your app proxy
|
467
|
+
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
468
|
![Creating an App Proxy](/images/app-proxy-screenshot.png)
|
464
469
|
|
465
470
|
App Bridge
|
@@ -472,6 +477,31 @@ Troubleshooting
|
|
472
477
|
|
473
478
|
see [TROUBLESHOOTING.md](https://github.com/Shopify/shopify_app/blob/master/docs/Troubleshooting.md)
|
474
479
|
|
480
|
+
Using Test Helpers inside your Application
|
481
|
+
-----------------------------------------
|
482
|
+
|
483
|
+
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`.
|
484
|
+
|
485
|
+
```ruby
|
486
|
+
require 'test_helper'
|
487
|
+
require 'action_controller'
|
488
|
+
require 'action_controller/base'
|
489
|
+
require 'shopify_app/test_helpers/webhook_verification_helper'
|
490
|
+
```
|
491
|
+
|
492
|
+
Or you can require in your `test/test_helper.rb`.
|
493
|
+
|
494
|
+
```ruby
|
495
|
+
ENV['RAILS_ENV'] ||= 'test'
|
496
|
+
require_relative '../config/environment'
|
497
|
+
require 'rails/test_help'
|
498
|
+
require 'byebug'
|
499
|
+
require 'shopify_app/test_helpers/all'
|
500
|
+
```
|
501
|
+
|
502
|
+
With `lib/shopify_app/test_helpers/all'` more tests can be added and will only need to be required in once in your library.
|
503
|
+
|
504
|
+
|
475
505
|
Testing an embedded app outside the Shopify admin
|
476
506
|
-------------------------------------------------
|
477
507
|
|
@@ -495,14 +525,22 @@ change to how session stores work. Here are the steps to migrate to 13.x
|
|
495
525
|
### Shop Model Changes (normally `app/models/shop.rb`)
|
496
526
|
- *CHANGE* `include ShopifyApp::SessionStorage` to `include ShopifyApp::ShopSessionStorage`
|
497
527
|
|
528
|
+
### Changes to the @shop_session instance variable (normally in `app/controllers/*.rb`)
|
529
|
+
- *CHANGE* if you are using shop sessions, `@shop_session` will need to be changed to `@current_shopify_session`.
|
530
|
+
|
531
|
+
### Changes to Rails `session`
|
532
|
+
- *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.
|
533
|
+
|
498
534
|
### Changes to `ShopifyApp::LoginProtection`
|
499
535
|
`ShopifyApp::LoginProtection`
|
500
536
|
|
501
|
-
if you are using `ShopifyApp::LoginProtection#
|
537
|
+
- CHANGE if you are using `ShopifyApp::LoginProtection#shopify_session` in your code, it will need to be
|
502
538
|
changed to `ShopifyApp::LoginProtection#activate_shopify_session`
|
539
|
+
- CHANGE if you are using `ShopifyApp::LoginProtection#clear_shop_session` in your code, it will need to be
|
540
|
+
changed to `ShopifyApp::LoginProtection#clear_shopify_session`
|
503
541
|
|
504
542
|
### Notes
|
505
|
-
You do not need a user model
|
543
|
+
You do not need a user model; a shop session is fine for most applications.
|
506
544
|
|
507
545
|
Questions or problems?
|
508
546
|
----------------------
|
@@ -540,7 +578,7 @@ Upgrading from 8.6 to 9.0.0
|
|
540
578
|
|
541
579
|
### Configuration change
|
542
580
|
|
543
|
-
Add an
|
581
|
+
Add an API version configuration in `config/initializers/shopify_app.rb`
|
544
582
|
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
583
|
```ruby
|
546
584
|
config.api_version = '2019-04'
|
@@ -548,7 +586,7 @@ config.api_version = '2019-04'
|
|
548
586
|
|
549
587
|
### Session storage change
|
550
588
|
|
551
|
-
You will need to add an `api_version` method to
|
589
|
+
You will need to add an `api_version` method to your session storage object. The default implementation for this is.
|
552
590
|
```ruby
|
553
591
|
def api_version
|
554
592
|
ShopifyApp.configuration.api_version
|
@@ -586,7 +624,7 @@ is changed to
|
|
586
624
|
|
587
625
|
### ShopifyAPI changes
|
588
626
|
|
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
|
627
|
+
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
628
|
|
591
629
|
[dashboard]:https://partners.shopify.com
|
592
630
|
[app-bridge]:https://help.shopify.com/en/api/embedded-apps/app-bridge
|
data/Rakefile
CHANGED
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)
|
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
<svg enable-background="new 0 0 1920 1080" version="1.1" viewBox="0 0 1920 1080" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><polygon points="1345 330.75 1345 437.24 1224.7 437.24 1224.7 676.56 873.52 676.56 874.04 643.85 1203.2 330.23" fill="#fff"/><path d="m1095.7 677.54c-18.553 0.074-37.107 0.163-55.66 0.126-18.553 0.056-37.107-0.188-55.66-0.233l-13.915-0.063-13.915 0.044-27.83 0.094c-18.553 0.128-37.107-5e-3 -55.66-0.056l-1.266-3e-3 3e-3 -1.259 0.047-22.532-0.093-22.532-0.068-11.266 6e-3 -11.266 0.019-22.532h2.703l0.111 22.532c0.053 7.511 0.06 15.022 0.038 22.532l-0.094 45.065-1.407-1.407c18.553 7e-3 37.107-0.041 55.66 0.086l27.83 0.131 13.915 0.066 13.915-0.028c18.553-8e-3 37.107-0.151 55.66-0.019 18.553 0.099 37.107 0.049 55.66-0.181v2.701z" fill="#0C1238"/><path d="m1225 677.54c-9.24 0.123-18.48 0.187-27.72 0.077l-13.86-0.213c-2.31-0.051-4.62-0.023-6.93 1e-3l-6.93 0.062c-9.24 0.156-18.48 0.076-27.72-0.054-2.31-0.034-4.62 1e-3 -6.93 2e-3l-6.93 0.121c-4.62 0.062-9.24-2e-3 -13.86 3e-3v-2.703c4.62-0.048 9.24-0.165 13.86-0.157l6.93 0.025c2.31 0.027 4.62 0.088 6.93 0.076 9.24-0.024 18.48-0.031 27.72 0.145 4.62 0.038 9.24 0.163 13.86 0.126l13.86-0.081c4.62-0.04 9.24 0.088 13.86 0.101 2.31 0.047 4.62-0.048 6.93-0.065 2.31-0.026 4.62-0.07 6.93-0.169v2.703z" fill="#0C1238"/><path d="m871.68 561.78l-0.13-115.72 0.07-115.72 1e-3 -1.414 1.411 3e-3 117.9 0.228 117.9-0.138 58.951-0.061 58.951 0.072 117.9 0.09 1.218 1e-3 4e-3 1.221 0.156 53.426-0.026 53.426h-2.703l-0.154-53.426 0.04-53.426 1.466 1.466-235.8-0.148-117.9-0.193-117.9 0.087 1.212-1.212-0.084 115.72c-0.058 19.286 0.032 38.573 0.074 57.859l0.15 57.859h-2.705z" fill="#0C1238"/><g fill="#E6E8F0"><circle cx="891.37" cy="344.49" r="6.812"/><circle cx="912.86" cy="345.01" r="6.812"/><circle cx="934.34" cy="345.54" r="6.812"/><path d="m1202.7 352.87h-186.64c-0.552 0-1-0.448-1-1v-11.624c0-0.552 0.448-1 1-1h186.64c0.552 0 1 0.448 1 1v11.624c0 0.552-0.448 1-1 1z" stroke="#F0F3F5" stroke-miterlimit="10"/><rect x="1288.6" y="339.25" width="17.816" height="13.624"/><path d="m1327.4 352.87h-15.816c-0.552 0-1-0.448-1-1v-11.624c0-0.552 0.448-1 1-1h15.816c0.552 0 1 0.448 1 1v11.624c0 0.552-0.447 1-1 1z"/></g><g fill="none" stroke="#8891EA" stroke-miterlimit="10" stroke-width="8"><path d="m1098.3 576.8c-24.295 0-43.99-19.695-43.99-43.99v-29.485c0-2.209 1.791-4 4-4h79.98c2.209 0 4 1.791 4 4v29.485c0 24.295-19.695 43.99-43.99 43.99z"/><path d="m1066 499.33v-12.41c0-17.804 14.433-32.237 32.237-32.237s32.237 14.433 32.237 32.237v12.41"/></g><circle cx="1098.3" cy="529.08" r="8.966" fill="#8891EA"/><line x1="1098.3" x2="1098.3" y1="529.08" y2="546.68" fill="#fff" stroke="#8891EA" stroke-linecap="round" stroke-miterlimit="10" stroke-width="8"/><polygon points="1416.1 676.19 1358 748.57 1416.1 749.77 1225 749.77 1225 659.42 1416.1 437.19" fill="#fff"/><path d="m1415.2 497.07l-0.12-59.83 1.472 1.472-95.89-0.052-47.945-0.135c-15.982-0.023-31.963-0.14-47.945-0.085l1.2-1.2 0.139 78.077c0.086 26.026 4e-3 52.052-0.039 78.077l-0.076 78.077c0.056 26.026 0.201 52.052 0.145 78.077l-1.368-1.368 38.25 0.017v2.703l-38.251 0.1-1.444 4e-3 -6e-3 -1.454c-0.102-26.026-0.045-52.052-0.026-78.077l0.068-78.077 0.067-78.077 0.191-78.077 3e-3 -1.15h1.147l47.945-0.013 47.945-0.051 95.89 0.089 1.121 1e-3 4e-3 1.125 0.226 59.83h-2.703z" fill="#0C1238"/><path d="m1417.9 518.33c0.051 19.268 0.165 38.536 0.128 57.804l-0.022 28.902-0.134 28.902-0.134 28.902 0.061 28.902 0.087 28.902 0.046 14.451-0.034 14.451-3e-3 1.353-1.347-3e-3c-22.64-0.042-45.28-0.192-67.919-0.118l-33.96 0.144-33.96-0.025v-2.703l33.96-0.143 33.96 0.01c11.32 0.049 22.64 0.1 33.96 0.078l33.96-2e-3 -1.409 1.409c-0.03-19.268 0.125-38.536 0.178-57.804l0.103-28.902-0.051-28.902-0.051-28.902 0.081-28.902c0.128-19.268-0.116-38.536-0.204-57.804h2.704z" fill="#0C1238"/><path d="m1400.3 458.72h-160.44c-0.552 0-1-0.448-1-1v-11.624c0-0.552 0.448-1 1-1h160.44c0.552 0 1 0.448 1 1v11.624c0 0.552-0.448 1-1 1z" fill="#E6E8F0" stroke="#F0F3F5" stroke-miterlimit="10"/><path d="m1238.5 467.44c13.587-0.084 27.173-0.121 40.76-0.055l20.38 0.141c6.793 0.061 13.587-0.03 20.38-0.038 13.587-0.116 27.173-0.022 40.76 0.038 6.793 0.029 13.587-0.022 20.38-0.082 6.793-0.046 13.587 0 20.38-5e-3v1.802c-13.587 0.111-27.173 0.144-40.76 0.036-13.587 2e-3 -27.173 0.027-40.76-0.09-6.793-0.025-13.587-0.117-20.38-0.088l-20.38 0.054c-6.793 0.022-13.587-0.048-20.38-0.067-6.793-7e-3 -13.587 0.107-20.38 0.154v-1.8z" fill="#E6E8F0"/><path d="m891.69 362.56c36.392-0.084 72.784-0.121 109.18-0.055l54.588 0.141c18.196 0.062 36.392-0.034 54.588-0.043l218.35-0.043v1.802c-36.392 0.111-72.784 0.144-109.18 0.036l-109.18-0.09-54.588-0.088-54.588 0.054-54.588-0.067-54.588 0.154v-1.801z" fill="#E6E8F0"/><g fill="none" stroke="#8891EA" stroke-miterlimit="10" stroke-width="6"><path d="m1320.6 638.41c-17.878 0-32.371-14.493-32.371-32.371v-21.697c0-1.626 1.318-2.943 2.943-2.943h58.854c1.626 0 2.943 1.318 2.943 2.943v21.697c1e-3 17.878-14.491 32.371-32.369 32.371z"/><path d="m1296.9 581.4v-9.132c0-13.101 10.62-23.722 23.722-23.722 13.101 0 23.722 10.621 23.722 23.722v9.132"/></g><circle cx="1320.6" cy="604.5" r="5.88" fill="#8891EA"/><line x1="1320.6" x2="1320.6" y1="603.3" y2="616.25" fill="#fff" stroke="#8891EA" stroke-linecap="round" stroke-miterlimit="10" stroke-width="6"/><path d="m966.35 697.36l-0.029 13.745c-0.01 1.145 0.011 2.291-0.023 3.436l-0.124 3.436c-0.103 2.291 0.022 4.582 0.121 6.872l-1.912-1.912c10.168-0.857 20.337-0.478 30.505-0.36 5.084 0.104 10.168 0.133 15.252 0.178 5.084 6e-3 10.168 0.199 15.252 0.287l7.626 0.168 7.626 0.264c2.542 0.09 5.084 0.032 7.626 0.023 2.542-0.035 5.084 0.047 7.626 0.065 10.168 0.377 20.337-0.052 30.505 0.201l7.626 0.04c2.542 6e-3 5.084-0.283 7.626-0.394 5.084-0.14 10.168-0.184 15.252-0.268 5.084-0.072 10.168-0.071 15.252-0.204 2.542-0.07 5.084-0.088 7.626-0.118 2.542-0.019 5.084 0.1 7.626 0.143 10.168 0.462 20.337-0.303 30.505 0.192 2.542 0.145 5.084 0.163 7.626 0.139 2.542 0 5.084-0.038 7.626-0.099l15.252-0.314v3.936l-15.252 0.106c-5.084 0.024-10.168 0.012-15.252 0.3-10.168 0.483-20.337-0.281-30.505-0.213-20.337-1.165-40.673 0.704-61.01-0.137-2.542 0.117-5.084 0.33-7.626 0.382-2.542 0.092-5.084 0.173-7.626-0.018s-5.084-0.219-7.626-0.183c-2.542-2e-3 -5.084 0.099-7.626 0.081-2.542-0.027-5.084 0.026-7.626-0.066-1.271-0.039-2.542-0.079-3.813-0.09-1.271-0.022-2.542-0.05-3.813 0.018-2.542 0.097-5.084 0.355-7.626 0.327-1.271-0.037-2.542-0.06-3.813-0.12l-3.813-0.238c-2.542-0.162-5.084-0.324-7.626-0.268-2.542 0.109-5.084-0.092-7.626-0.222-2.542-0.112-5.084-0.326-7.626-0.371-2.542-0.094-5.084-0.061-7.626-0.038-5.084 0.101-10.168 0.266-15.252 0.414-2.542 0.071-5.084 0.122-7.626 0.123l-7.626-0.19-1.598-0.04 0.032-1.527c0.047-2.291 0.153-4.582 9e-3 -6.872l-0.162-3.436c-0.047-1.145-0.04-2.291-0.062-3.436l-0.186-13.745h3.934z" fill="#E6E8F0"/><path d="m1434.8 722.88l16.096 0.019 8.048 0.01c2.683 0.018 5.365-0.029 8.048 0.05l-1.89 1.89c0.07-3.44 0.218-6.88 0.086-10.32l-0.312-10.32c-0.261-6.88-0.364-13.76-0.339-20.639l0.314-41.279c0.052-6.88 0.033-13.76 0.144-20.639l0.275-20.639c0.057-6.88 0.274-13.76 0.375-20.639 0.058-6.88-0.069-13.76 0.033-20.639l0.226-20.639-0.071-10.32-0.046-5.16 0.032-5.16 0.11-20.639c0.012-3.44 0.045-6.88-0.068-10.32-0.149-3.44-0.261-6.88-0.361-10.32l-0.328-41.279c-0.074-6.88-0.188-13.76-0.211-20.639 0.028-6.88 0.177-13.76 0.261-20.639l1.77 1.77c-4.37-0.095-8.74 1e-3 -13.111 1e-3l-13.111 0.063c-4.37 1e-3 -8.74 0.084-13.111 0.016l-13.111-0.231c-4.37-0.118-8.74-0.058-13.111-0.055-4.37-4e-3 -8.74 0.077-13.111 0.113l-26.221 0.29v-3.936l26.221-0.107 13.111-0.052c4.37-0.026 8.74 2e-3 13.111-0.14l13.111-0.262c4.37-0.066 8.74 0.04 13.111 0.051l26.221 0.283 2.211 0.024-0.016 2.172c-0.049 6.88-0.045 13.76-0.139 20.639-0.152 6.88-0.325 13.76-0.304 20.639l0.499 41.279c-0.024 1.72-0.037 3.44-0.138 5.16l-0.297 5.16c-0.137 3.44-0.045 6.88 0.01 10.32 0.12 6.88 0.479 13.76 0.59 20.639 0.273 6.88-0.127 13.76-0.227 20.639-0.014 6.88 0.146 13.76 0.091 20.639 0.051 6.88-0.202 13.76-0.162 20.639 0.04 3.44 0.226 6.88 0.324 10.32 0.061 3.44 4e-3 6.88-0.082 10.32l-0.356 10.32c-0.047 1.72-0.141 3.44-0.149 5.16l2e-3 5.16c-0.012 1.72 0.032 3.44-0.026 5.16l-0.164 5.16-0.335 10.32c-0.306 13.76 0.065 27.519 0.289 41.279 0.074 3.44 0.091 6.88 0.13 10.32 0.059 3.44-0.071 6.88-0.098 10.32l-0.153 10.32c-0.053 1.72 0.021 3.44 0.049 5.16l0.139 5.16 0.044 1.627-1.73 0.06c-2.683 0.093-5.365 0.065-8.048 0.1l-8.048 0.061-16.096 0.121v-3.941z" fill="#E6E8F0"/></svg>
|
1
|
+
<svg width="140" height="140" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M79 55a9 9 0 00-18 0v8h18v-8zm6 8v-8a15 15 0 00-30 0v8h-5a2 2 0 00-2 2v20a15 15 0 0015 15h14a15 15 0 0015-15V65a2 2 0 00-2-2h-5zM70 90a3 3 0 01-3-3V75a3 3 0 116 0v12a3 3 0 01-3 3z" fill="#8C9196"/></svg>
|
@@ -132,7 +132,8 @@
|
|
132
132
|
|
133
133
|
/* ITP 2.0 solution: handles cookie partitioning */
|
134
134
|
StorageAccessHelper.prototype.setUpHelper = function() {
|
135
|
-
|
135
|
+
var shopifyData = document.body.dataset;
|
136
|
+
return new ITPHelper({redirectUrl: shopifyData.shopOrigin + "/admin/apps/" + shopifyData.apiKey + shopifyData.returnTo});
|
136
137
|
}
|
137
138
|
|
138
139
|
StorageAccessHelper.prototype.setCookieAndRedirect = function() {
|
@@ -7,6 +7,7 @@ module ShopifyApp
|
|
7
7
|
included do
|
8
8
|
include ShopifyApp::Localization
|
9
9
|
include ShopifyApp::LoginProtection
|
10
|
+
include ShopifyApp::CsrfProtection
|
10
11
|
include ShopifyApp::EmbeddedApp
|
11
12
|
before_action :login_again_if_different_user_or_shop
|
12
13
|
around_action :activate_shopify_session
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShopifyApp
|
4
|
+
module RequireKnownShop
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
before_action :check_shop_domain
|
9
|
+
before_action :check_shop_known
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_shopify_domain
|
13
|
+
return if params[:shop].blank?
|
14
|
+
@shopify_domain ||= ShopifyApp::Utils.sanitize_shop_domain(params[:shop])
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def check_shop_domain
|
20
|
+
redirect_to(ShopifyApp.configuration.login_url) unless current_shopify_domain
|
21
|
+
end
|
22
|
+
|
23
|
+
def check_shop_known
|
24
|
+
@shop = SessionRepository.retrieve_shop_session_by_shopify_domain(current_shopify_domain)
|
25
|
+
redirect_to(shop_login) unless @shop
|
26
|
+
end
|
27
|
+
|
28
|
+
def shop_login
|
29
|
+
url = URI(ShopifyApp.configuration.login_url)
|
30
|
+
|
31
|
+
url.query = URI.encode_www_form(
|
32
|
+
shop: params[:shop],
|
33
|
+
return_to: request.fullpath,
|
34
|
+
)
|
35
|
+
|
36
|
+
url.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|