shopify_app 9.0.0 → 12.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/CHANGELOG.md +145 -0
- data/README.md +180 -126
- data/app/assets/javascripts/shopify_app/itp_helper.js +6 -6
- data/app/assets/javascripts/shopify_app/storage_access.js +36 -7
- data/app/controllers/concerns/shopify_app/authenticated.rb +1 -1
- data/app/controllers/shopify_app/callback_controller.rb +14 -5
- data/app/controllers/shopify_app/extension_verification_controller.rb +20 -0
- data/app/controllers/shopify_app/sessions_controller.rb +44 -18
- data/app/views/shopify_app/sessions/enable_cookies.html.erb +3 -1
- data/app/views/shopify_app/sessions/request_storage_access.html.erb +2 -1
- data/app/views/shopify_app/sessions/top_level_interaction.html.erb +1 -0
- data/app/views/shopify_app/shared/redirect.html.erb +1 -0
- data/config/locales/cs.yml +23 -0
- data/config/locales/da.yml +20 -0
- data/config/locales/de.yml +5 -5
- data/config/locales/en.yml +1 -1
- data/config/locales/es.yml +3 -3
- data/config/locales/fi.yml +20 -0
- data/config/locales/fr.yml +3 -3
- data/config/locales/hi.yml +23 -0
- data/config/locales/it.yml +2 -3
- data/config/locales/ja.yml +1 -1
- data/config/locales/ko.yml +19 -0
- data/config/locales/ms.yml +22 -0
- data/config/locales/nb.yml +21 -0
- data/config/locales/nl.yml +3 -3
- data/config/locales/pl.yml +21 -0
- data/config/locales/pt-BR.yml +9 -10
- data/config/locales/pt-PT.yml +22 -0
- data/config/locales/sv.yml +21 -0
- data/config/locales/th.yml +20 -0
- data/config/locales/tr.yml +22 -0
- data/config/locales/zh-CN.yml +3 -3
- data/config/locales/zh-TW.yml +1 -2
- data/docs/Quickstart.md +44 -16
- data/docs/Releasing.md +0 -1
- data/docs/install-on-dev-shop.png +0 -0
- data/docs/test-your-app.png +0 -0
- data/karma.conf.js +1 -0
- data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +2 -2
- data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +39 -0
- data/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +62 -0
- data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +0 -6
- data/lib/generators/shopify_app/install/install_generator.rb +27 -11
- data/lib/generators/shopify_app/install/templates/_flash_messages.html.erb +1 -17
- data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +11 -10
- data/lib/generators/shopify_app/install/templates/flash_messages.js +26 -0
- data/lib/generators/shopify_app/install/templates/shopify_app.js +15 -0
- data/lib/generators/shopify_app/install/templates/shopify_app.rb +6 -3
- data/lib/generators/shopify_app/install/templates/shopify_app_index.js +2 -0
- data/lib/generators/shopify_app/install/templates/shopify_provider.rb +1 -0
- data/lib/generators/shopify_app/install/templates/user_agent.rb +5 -0
- data/lib/generators/shopify_app/user_model/templates/db/migrate/create_users.erb +16 -0
- data/lib/generators/shopify_app/user_model/templates/user.rb +7 -0
- data/lib/generators/shopify_app/user_model/templates/users.yml +4 -0
- data/lib/generators/shopify_app/user_model/user_model_generator.rb +38 -0
- data/lib/shopify_app.rb +46 -29
- data/lib/shopify_app/configuration.rb +24 -9
- data/lib/shopify_app/controller_concerns/login_protection.rb +53 -7
- data/lib/shopify_app/engine.rb +4 -0
- data/lib/shopify_app/managers/webhooks_manager.rb +1 -1
- data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +33 -0
- data/lib/shopify_app/session/in_memory_session_store.rb +1 -1
- data/lib/shopify_app/session/session_repository.rb +2 -2
- data/lib/shopify_app/session/session_storage.rb +10 -22
- data/lib/shopify_app/session/storage_strategies/shop_storage_strategy.rb +23 -0
- data/lib/shopify_app/session/storage_strategies/user_storage_strategy.rb +24 -0
- data/lib/shopify_app/utils.rb +7 -0
- data/lib/shopify_app/version.rb +1 -1
- data/package-lock.json +7212 -11
- data/package.json +9 -9
- data/service.yml +1 -1
- data/shopify_app.gemspec +10 -5
- data/translation.yml +1 -1
- data/yarn.lock +2555 -1886
- metadata +115 -19
- data/lib/generators/shopify_app/home_controller/templates/shopify_app_ready_script.html.erb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3552d2c9437c900a3217f00b142d81d187cfad26a4a3ea84ca3e1b64cb03dc14
|
4
|
+
data.tar.gz: 6aa9bde06b9635c5d61c6c01271ee073f54b7473ee4dbce8c4cf3af9f776d1aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b1c648bd6ecc8ed980b1f15354edb3a85856a4d80c5598b020cc4d9dd0bec1bfb90da82c01bcefeb9deb75376fc023d43f5b3b406aaecc77fab03061c63c8fb
|
7
|
+
data.tar.gz: e3647c88c1b956c6ec76c8f0414a4f4c9e4ae3f97b5502adbd9e9507b7dbd94559d6905a3175f9a45267d5b6cd165ad6394bce08cb91530f8c777624c5ba9522
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,148 @@
|
|
1
|
+
12.0.5
|
2
|
+
-----
|
3
|
+
* Updating shopify_api gem to 9.0.1
|
4
|
+
|
5
|
+
12.0.4
|
6
|
+
------
|
7
|
+
* Reverts reverted PR (#895) #897
|
8
|
+
|
9
|
+
12.0.3
|
10
|
+
------
|
11
|
+
* Moves samesite middleware higher in the stack #898
|
12
|
+
* Fix issue where not redirecting user to granted storage page casues infinite loop #900
|
13
|
+
|
14
|
+
12.0.2
|
15
|
+
------
|
16
|
+
* Reverts "Fix for return_to in safari after enable_cookies/granted_storage_access" introduced in 12.0.1
|
17
|
+
|
18
|
+
12.0.1
|
19
|
+
------
|
20
|
+
* disable samesite cookie middleware in tests
|
21
|
+
* middleware compatibility for ruby 2.3
|
22
|
+
* samesite cookie fixes for javascript libraries
|
23
|
+
* change generators to add AppBridge instead of EASDK
|
24
|
+
* Fix for return_to in safari after enable_cookies/granted_storage_access
|
25
|
+
|
26
|
+
12.0.0
|
27
|
+
-----
|
28
|
+
* Updating shopify_api gem to 9.0.0
|
29
|
+
|
30
|
+
11.7.1
|
31
|
+
-----
|
32
|
+
* Fix to allow SessionStorage to be flexible on what model names that the are used for storing shop and user data
|
33
|
+
|
34
|
+
11.7.0
|
35
|
+
-----
|
36
|
+
* Move ExtensionVerificationController from engine to app controllers, as being in the engine makes ActionController::Base get loaded before app initiates [#855](https://github.com/Shopify/shopify_app/pull/855)
|
37
|
+
* Add back per-user token support (added in 11.5.0, reverted in 11.5.1)
|
38
|
+
* If you have an override on the `self.store(auth_session)` method on your `SessionRepository` model, the method signature must be changed as according to this [change](https://github.com/Shopify/shopify_app/pull/856/files#diff-deaed2b262ec885f4e36de05621e41eaR18)
|
39
|
+
|
40
|
+
11.6.0
|
41
|
+
-----
|
42
|
+
* Enable SameSite=None; Secure by default on all cookies for embedded apps [#851](https://github.com/Shopify/shopify_app/pull/851)
|
43
|
+
* Ensures compatibility of embedded apps with upcoming Chrome version 80 changes to cookie behaviour
|
44
|
+
* Configurable via `ShopifyApp.configuration.enable_same_site_none` (default true for embedded apps)
|
45
|
+
|
46
|
+
11.5.1
|
47
|
+
-----
|
48
|
+
* Revert per-user token support temporarily
|
49
|
+
|
50
|
+
11.5.0
|
51
|
+
-----
|
52
|
+
* Modularizes durable session storage
|
53
|
+
* Introduces per-user token support and user session management
|
54
|
+
|
55
|
+
11.4.0
|
56
|
+
-----
|
57
|
+
* Remove `dotenv-rails` dependency. [#835](https://github.com/Shopify/shopify_app/pull/835)
|
58
|
+
|
59
|
+
11.3.2
|
60
|
+
-----
|
61
|
+
* Fix hosts generator in Rails 5 [#823](https://github.com/Shopify/shopify_app/pull/823)
|
62
|
+
|
63
|
+
11.3.1
|
64
|
+
-----
|
65
|
+
* Bump browser_sniffer version to 1.1.3 [#824](https://github.com/Shopify/shopify_app/pull/824)
|
66
|
+
|
67
|
+
11.3.0
|
68
|
+
-----
|
69
|
+
* Update assets to be compatible with Rails 6 [#808](https://github.com/Shopify/shopify_app/pull/808)
|
70
|
+
|
71
|
+
11.2.1
|
72
|
+
-----
|
73
|
+
* Adds ngrok whitelist in development [#802](https://github.com/Shopify/shopify_app/pull/802)
|
74
|
+
|
75
|
+
11.2.0
|
76
|
+
-----
|
77
|
+
|
78
|
+
* Bump omniauth-shopify-oauth2 gem to v2.2.0
|
79
|
+
|
80
|
+
11.1.0
|
81
|
+
-----
|
82
|
+
|
83
|
+
* Add Webmock and Pry as development dependencies
|
84
|
+
* Update install generator to leverage updates to ShopifyAPI::ApiVersion add in v8.0.0 of the shopify_api gem [#790](https://github.com/Shopify/shopify_app/pull/790)
|
85
|
+
|
86
|
+
|
87
|
+
11.0.2
|
88
|
+
-----
|
89
|
+
|
90
|
+
* Lock shopify_api gem dependency to `~> 7.0` from `>= 7.0.0`.
|
91
|
+
* Remove flakey JS Tests
|
92
|
+
* bump sqlite3 development dependency to `~>1.4` from `~> 1.3.6`. [#789](https://github.com/Shopify/shopify_app/pull/789)
|
93
|
+
|
94
|
+
11.0.1
|
95
|
+
-----
|
96
|
+
|
97
|
+
* Add dotenv-rails gem to install generator, so apps fetch credentials from `.env` by default: [#776](https://github.com/Shopify/shopify_app/pull/776)
|
98
|
+
|
99
|
+
11.0.0
|
100
|
+
-----
|
101
|
+
|
102
|
+
* Rename `login_url` method to `login_url_with_optional_shop` to avoid ambiguity with Rails' route helper method of the
|
103
|
+
same name (see [#585](https://github.com/Shopify/shopify_app/pull/585)).
|
104
|
+
|
105
|
+
10.0.0
|
106
|
+
-----
|
107
|
+
|
108
|
+
* Make sure OAuth-related redirects return user to originally requested URL once authenticated
|
109
|
+
* Add/update translations
|
110
|
+
* Update README to clarify nested routes
|
111
|
+
* Remove example app. Users should instead use the generators to scaffold an example app.
|
112
|
+
* Bump required Rails version to `> 5.2.1` to ensure `5.2.1.1` or greater is used. This ensures two things:
|
113
|
+
* Apps are not vulnerable to [CVE-2018-16476](https://nvd.nist.gov/vuln/detail/CVE-2018-16476)
|
114
|
+
* Webhook payloads, from Shopify for API version 2019-07, which are processed in ActiveJob background jobs (the
|
115
|
+
default behaviour of shopify_app's WebhooksController) are compatible, due to how ActiveJob versions prior to
|
116
|
+
5.2.1.1 process GlobalIDs encoded as string in job parameters. This prevents the
|
117
|
+
[exceptions reported previously](https://github.com/Shopify/shopify_app/issues/600).
|
118
|
+
|
119
|
+
9.0.4
|
120
|
+
-----
|
121
|
+
|
122
|
+
* Fix returning to a deep link after authentication [#746](https://github.com/Shopify/shopify_app/pull/746)
|
123
|
+
|
124
|
+
9.0.3
|
125
|
+
-----
|
126
|
+
|
127
|
+
* Add `meta viewport` tags to fix mobile responsive problems
|
128
|
+
* Remove outdated, extraneous `yarn.lock` file (and rely on existing `package-lock.json` instead)
|
129
|
+
* Move inline js to a js asset file
|
130
|
+
* Minor documentation corrections
|
131
|
+
|
132
|
+
9.0.2
|
133
|
+
-----
|
134
|
+
|
135
|
+
* Update browser_sniffer to fix unnecessary ITP flows in Shopify Mobile
|
136
|
+
* Add additional languages to translation.yml
|
137
|
+
* Minor documentation corrections
|
138
|
+
|
139
|
+
9.0.1
|
140
|
+
-----
|
141
|
+
|
142
|
+
* Minor documentation corrections
|
143
|
+
* Handle `Webhook.all` returning `nil` and raising on `index_by`
|
144
|
+
|
145
|
+
|
1
146
|
9.0.0
|
2
147
|
-----
|
3
148
|
|
data/README.md
CHANGED
@@ -12,73 +12,44 @@ Shopify Application Rails engine and generator
|
|
12
12
|
|
13
13
|
Table of Contents
|
14
14
|
-----------------
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
* [**ShopifyApp::SessionRepository**](#shopifyappsessionrepository)
|
34
|
-
* [**Authenticated**](#authenticated)
|
35
|
-
* [**AppProxyVerification**](#appproxyverification)
|
36
|
-
* [Recommended Usage](#recommended-usage)
|
37
|
-
* [**Upgrading from 8.6 to 9.0.0**](#upgrading-from-86-to-900)
|
38
|
-
* [**Troubleshooting**](#troubleshooting)
|
39
|
-
* [Generator shopify_app:install hangs](#generator-shopify_appinstall-hangs)
|
40
|
-
* [**Testing an embedded app outside the Shopify admin**](#testing-an-embedded-app-outside-the-shopify-admin)
|
41
|
-
* [**Questions or problems?**](#questions-or-problems)
|
42
|
-
|
43
|
-
|
44
|
-
Description
|
15
|
+
- [Introduction](#introduction)
|
16
|
+
- [Become a Shopify App Developer](#become-a-shopify-app-developer)
|
17
|
+
- [Installation](#installation)
|
18
|
+
- [Generators](#generators)
|
19
|
+
- [Mounting the Engine](#mounting-the-engine)
|
20
|
+
- [Authentication](#authentication)
|
21
|
+
- [WebhooksManager](#webhooksmanager)
|
22
|
+
- [ScripttagsManager](#scripttagsmanager)
|
23
|
+
- [RotateShopifyTokenJob](#rotateshopifytokenjob)
|
24
|
+
- [App Tunneling](#app-tunneling)
|
25
|
+
- [AppProxyVerification](#appproxyverification)
|
26
|
+
- [Troubleshooting](#troubleshooting)
|
27
|
+
- [Testing an embedded app outside the Shopify admin](#testing-an-embedded-app-outside-the-shopify-admin)
|
28
|
+
- [Questions or problems?](#questions-or-problems-)
|
29
|
+
- [Rails 6 Compatibility](#rails-6-compatibility)
|
30
|
+
- [Upgrading from 8.6 to 9.0.0](#upgrading-from-86-to-900)
|
31
|
+
|
32
|
+
Introduction
|
45
33
|
-----------
|
46
|
-
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).
|
34
|
+
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).
|
47
35
|
|
48
|
-
|
36
|
+
*Note: It's recommended to use this on a new Rails project, so that the generator won't overwrite/delete your files.*
|
49
37
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
Quickstart
|
54
|
-
----------
|
55
|
-
|
56
|
-
Check out this screencast on how to create and deploy a new Shopify App to Heroku in 5 minutes:
|
38
|
+
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:
|
57
39
|
|
58
40
|
[https://www.youtube.com/watch?v=yGxeoAHlQOg](https://www.youtube.com/watch?v=yGxeoAHlQOg)
|
59
41
|
|
60
|
-
|
61
|
-
|
62
|
-
App Tunneling
|
63
|
-
-------------
|
64
|
-
|
65
|
-
Your local app needs to be accessible from the public Internet in order to install it on a shop, use the [App Proxy Controller](#app-proxy-controller-generator) or receive Webhooks. Use a tunneling service like [ngrok](https://ngrok.com/), [Forward](https://forwardhq.com/), [Beeceptor](https://beeceptor.com/), [Mockbin](http://mockbin.org/), [Hookbin](https://hookbin.com/), etc.
|
66
|
-
|
67
|
-
For example with [ngrok](https://ngrok.com/), run this command to set up proxying to Rails' default port:
|
68
|
-
|
69
|
-
```sh
|
70
|
-
ngrok http 3000
|
71
|
-
```
|
72
|
-
|
73
|
-
Becoming a Shopify App Developer
|
42
|
+
Become a Shopify App Developer
|
74
43
|
--------------------------------
|
75
|
-
If you don't have a Shopify Partner account
|
44
|
+
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
|
+
|
46
|
+
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.
|
76
47
|
|
77
|
-
|
48
|
+
To create an application for development set your new app's `App URL` to the URL provided by [your tunnel](#app-tunneling), ensuring that you use `https://`. If you are not planning to embed your app inside the Shopify admin or receive webhooks, set your redirect URL to `http://localhost:3000/` and the `Whitelisted redirection URL(s)` to contain `<App URL>/auth/shopify/callback`.
|
78
49
|
|
79
50
|
Installation
|
80
51
|
------------
|
81
|
-
To get started add shopify_app to your Gemfile and bundle install
|
52
|
+
To get started add `shopify_app` to your Gemfile and run `bundle install`:
|
82
53
|
|
83
54
|
``` sh
|
84
55
|
# Create a new rails app
|
@@ -90,7 +61,7 @@ $ echo "gem 'shopify_app'" >> Gemfile
|
|
90
61
|
$ bundle install
|
91
62
|
```
|
92
63
|
|
93
|
-
Now we are ready to run any of the shopify_app
|
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.
|
94
65
|
|
95
66
|
|
96
67
|
#### Rails Compatibility
|
@@ -103,13 +74,26 @@ Generators
|
|
103
74
|
|
104
75
|
### Default Generator
|
105
76
|
|
106
|
-
The default generator will run the `install`, `shop`, and `home_controller` generators. This is the recommended way to start
|
77
|
+
The default generator will run the `install`, `shop`, and `home_controller` generators. This is the recommended way to start a new app from scratch:
|
107
78
|
|
108
79
|
```sh
|
109
|
-
$ rails generate shopify_app
|
80
|
+
$ rails generate shopify_app
|
110
81
|
```
|
111
82
|
|
112
|
-
After running the generator, you will need to run `
|
83
|
+
After running the generator, you will need to run `rails db:migrate` to add new tables to your database. You can start your app with `bundle exec rails server` and install your app by visiting `http://localhost` in your web browser.
|
84
|
+
|
85
|
+
### API Keys
|
86
|
+
|
87
|
+
The default and install generators have been updated to source Shopify API key and secret from an Environment (`.env`) variables file, which you will need to create with the following format:
|
88
|
+
|
89
|
+
```
|
90
|
+
SHOPIFY_API_KEY=your api key
|
91
|
+
SHOPIFY_API_SECRET=your api secret
|
92
|
+
```
|
93
|
+
|
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.
|
95
|
+
|
96
|
+
**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.**
|
113
97
|
|
114
98
|
### Install Generator
|
115
99
|
|
@@ -118,7 +102,7 @@ $ rails generate shopify_app:install
|
|
118
102
|
|
119
103
|
# or optionally with arguments:
|
120
104
|
|
121
|
-
$ rails generate shopify_app:install
|
105
|
+
$ rails generate shopify_app:install
|
122
106
|
```
|
123
107
|
|
124
108
|
Other options include:
|
@@ -135,24 +119,13 @@ The generator adds ShopifyApp and the required initializers to the host Rails ap
|
|
135
119
|
After running the `install` generator, you can start your app with `bundle exec rails server` and install your app by visiting localhost.
|
136
120
|
|
137
121
|
|
138
|
-
### Shop Model Generator
|
139
|
-
|
140
|
-
```sh
|
141
|
-
$ rails generate shopify_app:shop_model
|
142
|
-
```
|
143
|
-
|
144
|
-
The `install` generator doesn't create any database tables or models for you. If you are starting a new app its quite likely that you will want a shops table and model to store the tokens when your app is installed (most of our internally developed apps do!). This generator creates a shop model and a migration. This model includes the `ShopifyApp::SessionStorage` concern which adds two methods to make it compatible as a `SessionRepository`. After running this generator you'll notice the `session_repository` in your `config/initializers/shopify_app.rb` will be set to the `Shop` model. This means that internally ShopifyApp will try and load tokens from this model.
|
145
|
-
|
146
|
-
*Note that you will need to run rake db:migrate after this generator*
|
147
|
-
|
148
|
-
|
149
122
|
### Home Controller Generator
|
150
123
|
|
151
124
|
```sh
|
152
125
|
$ rails generate shopify_app:home_controller
|
153
126
|
```
|
154
127
|
|
155
|
-
This generator creates an example home controller and view which fetches and displays products using the
|
128
|
+
This generator creates an example home controller and view which fetches and displays products using the Shopify API
|
156
129
|
|
157
130
|
|
158
131
|
### App Proxy Controller Generator
|
@@ -163,6 +136,13 @@ $ rails generate shopify_app:app_proxy_controller
|
|
163
136
|
|
164
137
|
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
|
165
138
|
|
139
|
+
### Marketing Extension Generator
|
140
|
+
|
141
|
+
```sh
|
142
|
+
$ rails generate shopify_app:add_marketing_activity_extension
|
143
|
+
```
|
144
|
+
|
145
|
+
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.
|
166
146
|
|
167
147
|
### Controllers, Routes and Views
|
168
148
|
|
@@ -207,6 +187,19 @@ provider :shopify,
|
|
207
187
|
callback_path: '/nested/auth/shopify/callback'
|
208
188
|
```
|
209
189
|
|
190
|
+
You may also need to change your `config/routes.rb` to render a view for `/nested`, since this is what will be rendered in the Shopify Admin of any shops that have installed your app. The engine itself doesn't have a view for this, so you'll need something like this:
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
# config/routes.rb
|
194
|
+
Rails.application.routes.draw do
|
195
|
+
root :to => 'something_else#index'
|
196
|
+
get "/nested", to: "home#index"
|
197
|
+
mount ShopifyApp::Engine, at: '/nested'
|
198
|
+
end
|
199
|
+
```
|
200
|
+
|
201
|
+
Finally, note that if you do this, to add your app to a store, you must navigate to `/nested` in order to render the `Enter your shop domain to log in or install this app.` UI.
|
202
|
+
|
210
203
|
### Custom login URL
|
211
204
|
|
212
205
|
While you can customize the login view by creating a `/app/views/shopify_app/sessions/new.html.erb` file, you may also want to customize the URL entirely. You can modify your `shopify_app.rb` initializer to provide a custom `login_url` e.g.:
|
@@ -217,37 +210,93 @@ ShopifyApp.configure do |config|
|
|
217
210
|
end
|
218
211
|
```
|
219
212
|
|
220
|
-
|
221
|
-
|
222
|
-
|
213
|
+
Authentication
|
214
|
+
--------------
|
215
|
+
|
216
|
+
### ShopifyApp::SessionRepository
|
217
|
+
|
218
|
+
`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.
|
219
|
+
|
220
|
+
If you only run the install generator then by default you will have an in memory store but it **won't work** on multi-server environments including Heroku. For multi-server environments, implement one of the following token-storage strategies.
|
221
|
+
|
222
|
+
#### Shop-based token storage
|
223
|
+
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.
|
224
|
+
```sh
|
225
|
+
$ rails generate shopify_app:shop_model
|
226
|
+
```
|
227
|
+
This will generate a shop model which will be the storage for the tokens necessary for authentication.
|
228
|
+
|
229
|
+
#### User-based token storage
|
230
|
+
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.
|
231
|
+
```sh
|
232
|
+
$ rails generate shopify_app:user_model
|
233
|
+
```
|
234
|
+
This will generate a user model which will be the storage for the tokens necessary for authentication.
|
235
|
+
|
236
|
+
The current Shopify user will be stored in the rails session at `session[:shopify_user]`
|
237
|
+
|
238
|
+
In this mode, The `self.store(auth_session, *args)` will be invoked with a Shopify User object hash, which is then used to store the token as part of a user record, rather than a store record.
|
239
|
+
|
240
|
+
This will change the type of token that Shopify returns and it will only be valid for a short time. Read more about `Online access` [here](https://help.shopify.com/api/getting-started/authentication/oauth). Note that this means you won't be able to use this token to respond to Webhooks.
|
241
|
+
|
242
|
+
#### Migrating from shop-based to user-based token strategy
|
243
|
+
After running the generator, ensure that configuration settings are successfully changed:
|
223
244
|
|
224
245
|
```ruby
|
246
|
+
# In the `omniauth.rb` initializer:
|
225
247
|
provider :shopify,
|
226
248
|
ShopifyApp.configuration.api_key,
|
227
249
|
ShopifyApp.configuration.secret,
|
228
250
|
scope: ShopifyApp.configuration.scope,
|
229
251
|
per_user_permissions: true
|
252
|
+
|
253
|
+
# In the `shopify_app.rb` initializer:
|
254
|
+
config.session_repository = 'User'
|
255
|
+
config.per_user_tokens = true
|
230
256
|
```
|
231
257
|
|
232
|
-
|
258
|
+
### Authenticated
|
233
259
|
|
234
|
-
|
260
|
+
The engine provides a `ShopifyApp::Authenticated` concern which should be included in any controller that is intended to be behind Shopify OAuth. It adds `before_action`s to ensure that the user is authenticated and will redirect to the Shopify login page if not. It is best practice to include this concern in a base controller inheriting from your `ApplicationController`, from which all controllers that require Shopify authentication inherit.
|
235
261
|
|
236
|
-
|
237
|
-
|
262
|
+
For backwards compatibility, the engine still provides a controller called `ShopifyApp::AuthenticatedController` which includes the `ShopifyApp::Authenticated` concern. Note that it inherits directly from `ActionController::Base`, so you will not be able to share functionality between it and your application's `ApplicationController`.
|
263
|
+
|
264
|
+
### AfterAuthenticate Job
|
238
265
|
|
239
|
-
|
266
|
+
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:
|
240
267
|
|
241
268
|
```ruby
|
242
269
|
ShopifyApp.configure do |config|
|
243
|
-
config.
|
244
|
-
config.api_key = ENV['SHOPIFY_CLIENT_API_KEY']
|
245
|
-
config.secret = ENV['SHOPIFY_CLIENT_API_SECRET']
|
246
|
-
config.scope = 'read_customers, write_products'
|
247
|
-
config.embedded_app = true
|
270
|
+
config.after_authenticate_job = { job: "Shopify::AfterAuthenticateJob" }
|
248
271
|
end
|
249
272
|
```
|
250
273
|
|
274
|
+
The job can be configured as either a class or a class name string.
|
275
|
+
|
276
|
+
If you need the job to run synchronously add the `inline` flag:
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
ShopifyApp.configure do |config|
|
280
|
+
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
|
281
|
+
end
|
282
|
+
```
|
283
|
+
|
284
|
+
We've also provided a generator which creates a skeleton job and updates the initializer for you:
|
285
|
+
|
286
|
+
```
|
287
|
+
bin/rails g shopify_app:add_after_authenticate_job
|
288
|
+
```
|
289
|
+
|
290
|
+
If you want to perform that action only once, e.g. send a welcome email to the user when they install the app, you should make sure that this action is idempotent, meaning that it won't have an impact if run multiple times.
|
291
|
+
|
292
|
+
API Versioning
|
293
|
+
--------------
|
294
|
+
|
295
|
+
Shopify's API is versioned, and you can [read about that process in the Shopify Developers documentation page](https://shopify.dev/concepts/about-apis/versioning).
|
296
|
+
|
297
|
+
Since shopify_app gem version 1.11.0, the included shopify_api gem has also been updated to allow you to easily set and switch what version of the Shopify API you want your app or service to use, as well as surface warnings to Rails apps about [deprecated endpoints, GraphQL fields and more](https://shopify.dev/concepts/about-apis/versioning#deprecation-practices).
|
298
|
+
|
299
|
+
See the [shopify_api gem README](https://github.com/Shopify/shopify_api/) for more details.
|
251
300
|
|
252
301
|
WebhooksManager
|
253
302
|
---------------
|
@@ -284,7 +333,7 @@ ShopifyApp.configure do |config|
|
|
284
333
|
end
|
285
334
|
```
|
286
335
|
|
287
|
-
If you'd rather implement your own controller then you'll want to use the
|
336
|
+
If you'd rather implement your own controller then you'll want to use the WebhookVerification module to verify your webhooks, example:
|
288
337
|
|
289
338
|
```ruby
|
290
339
|
class CustomWebhooksController < ApplicationController
|
@@ -340,31 +389,6 @@ Scripttags are created in the same way as the Webhooks, with a background job wh
|
|
340
389
|
|
341
390
|
If `src` responds to `call` its return value will be used as the scripttag's source. It will be called on scripttag creation and deletion.
|
342
391
|
|
343
|
-
AfterAuthenticate Job
|
344
|
-
---------------------
|
345
|
-
|
346
|
-
If your app needs to perform specific actions after it is installed 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:
|
347
|
-
|
348
|
-
```ruby
|
349
|
-
ShopifyApp.configure do |config|
|
350
|
-
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob }
|
351
|
-
end
|
352
|
-
```
|
353
|
-
|
354
|
-
If you need the job to run synchronously add the `inline` flag:
|
355
|
-
|
356
|
-
```ruby
|
357
|
-
ShopifyApp.configure do |config|
|
358
|
-
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
|
359
|
-
end
|
360
|
-
```
|
361
|
-
|
362
|
-
We've also provided a generator which creates a skeleton job and updates the initializer for you:
|
363
|
-
|
364
|
-
```
|
365
|
-
bin/rails g shopify_app:add_after_authenticate_job
|
366
|
-
```
|
367
|
-
|
368
392
|
RotateShopifyTokenJob
|
369
393
|
---------------------
|
370
394
|
|
@@ -391,19 +415,18 @@ The generated rake task will be found at `lib/tasks/shopify/rotate_shopify_token
|
|
391
415
|
strategy.options[:old_client_secret] = ShopifyApp.configuration.old_secret
|
392
416
|
```
|
393
417
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
`ShopifyApp::SessionRepository` allows you as a developer to define how your sessions are retrieved and stored 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(shopify_session)` which stores the session and returns a unique identifier and `self.retrieve(id)` which returns a `ShopifyAPI::Session` for the passed id. See either the `ShopifyApp::InMemorySessionStore` class or the `ShopifyApp::SessionStorage` concern for examples.
|
418
|
+
App Tunneling
|
419
|
+
-------------
|
398
420
|
|
399
|
-
|
421
|
+
Your local app needs to be accessible from the public Internet in order to install it on a Shopify store, to use the [App Proxy Controller](#app-proxy-controller-generator) or receive Webhooks.
|
400
422
|
|
401
|
-
|
402
|
-
-------------
|
423
|
+
Use a tunneling service like [ngrok](https://ngrok.com/), [Forward](https://forwardhq.com/), [Beeceptor](https://beeceptor.com/), [Mockbin](http://mockbin.org/), or [Hookbin](https://hookbin.com/) to make your development environment accessible to the internet.
|
403
424
|
|
404
|
-
|
425
|
+
For example with [ngrok](https://ngrok.com/), run this command to set up a tunnel proxy to Rails' default port:
|
405
426
|
|
406
|
-
|
427
|
+
```sh
|
428
|
+
ngrok http 3000
|
429
|
+
```
|
407
430
|
|
408
431
|
AppProxyVerification
|
409
432
|
--------------------
|
@@ -423,9 +446,14 @@ class ReviewsController < ApplicationController
|
|
423
446
|
end
|
424
447
|
```
|
425
448
|
|
426
|
-
Create your app proxy url in the [Shopify Partners' Dashboard]
|
449
|
+
Create your app proxy url in the [Shopify Partners' Dashboard][dashboard], making sure to point it to `https://your_app_website.com/app_proxy`.
|
427
450
|
![Creating an App Proxy](/images/app-proxy-screenshot.png)
|
428
451
|
|
452
|
+
App Bridge
|
453
|
+
---
|
454
|
+
|
455
|
+
A basic example of using [App Bridge][app-bridge] is included in the install generator. An app instance is automatically initialized in [shopify_app.js](https://github.com/Shopify/shopify_app/blob/master/lib/generators/shopify_app/install/templates/shopify_app.js) and [flash_messages.js](https://github.com/Shopify/shopify_app/blob/master/lib/generators/shopify_app/install/templates/flash_messages.js) converts Rails [flash messages](https://api.rubyonrails.org/classes/ActionDispatch/Flash.html) to App Bridge Toast actions automatically. By default, this library is included via [unpkg in the embedded_app layout](https://github.com/Shopify/shopify_app/blob/master/lib/generators/shopify_app/install/templates/embedded_app.html.erb#L27). For more advanced uses it is recommended to [install App Bridge via npm or yarn](https://help.shopify.com/en/api/embedded-apps/app-bridge/getting-started#set-up-shopify-app-bridge-in-your-app).
|
456
|
+
|
429
457
|
Troubleshooting
|
430
458
|
---------------
|
431
459
|
|
@@ -446,6 +474,29 @@ Questions or problems?
|
|
446
474
|
- [Ask questions!](https://ecommerce.shopify.com/c/shopify-apis-and-technology)
|
447
475
|
- [Read the docs!](https://help.shopify.com/api/guides)
|
448
476
|
|
477
|
+
Upgrading to 11.7.0
|
478
|
+
---------------------------
|
479
|
+
|
480
|
+
### Session storage method signature breaking change
|
481
|
+
If you override `def self.store(auth_session)` method in your session storage model (e.g. Shop), the method signature has changed to `def self.store(auth_session, *args)` in order to support user-based token storage. Please update your method signature to include the second argument.
|
482
|
+
|
483
|
+
Rails 6 Compatibility
|
484
|
+
---------------------
|
485
|
+
|
486
|
+
### Disable Webpacker
|
487
|
+
If you are using sprockets in rails 6 or want to generate a shopify_app without webpacker run the install task by running
|
488
|
+
|
489
|
+
```
|
490
|
+
SHOPIFY_APP_DISABLE_WEBPACKER=1 rails generate shopify_app
|
491
|
+
```
|
492
|
+
|
493
|
+
and then in your ShopifyApp configuration block, add
|
494
|
+
|
495
|
+
```
|
496
|
+
ShopifyApp.configure do |config|
|
497
|
+
config.disable_webpacker = true
|
498
|
+
end
|
499
|
+
```
|
449
500
|
|
450
501
|
Upgrading from 8.6 to 9.0.0
|
451
502
|
---------------------------
|
@@ -453,14 +504,14 @@ Upgrading from 8.6 to 9.0.0
|
|
453
504
|
### Configuration change
|
454
505
|
|
455
506
|
Add an api version configuration in `config/initializers/shopify_app.rb`
|
456
|
-
Set this to the version you want to run against by default
|
507
|
+
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.
|
457
508
|
```ruby
|
458
509
|
config.api_version = '2019-04'
|
459
510
|
```
|
460
511
|
|
461
512
|
### Session storage change
|
462
513
|
|
463
|
-
You will need to add an `api_version` method to you session storage object. The default
|
514
|
+
You will need to add an `api_version` method to you session storage object. The default implementation for this is.
|
464
515
|
```ruby
|
465
516
|
def api_version
|
466
517
|
ShopifyApp.configuration.api_version
|
@@ -469,7 +520,7 @@ end
|
|
469
520
|
|
470
521
|
### Generated file change
|
471
522
|
|
472
|
-
`embedded_app.html.erb` the
|
523
|
+
`embedded_app.html.erb` the usage of `shop_session.url` needs to be changed to `shop_session.domain`
|
473
524
|
```erb
|
474
525
|
<script type="text/javascript">
|
475
526
|
ShopifyApp.init({
|
@@ -498,4 +549,7 @@ is changed to
|
|
498
549
|
|
499
550
|
### ShopifyAPI changes
|
500
551
|
|
501
|
-
You will need to also follow the ShopifyAPI [upgrade guide](https://github.com/
|
552
|
+
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.
|
553
|
+
|
554
|
+
[dashboard]:https://partners.shopify.com
|
555
|
+
[app-bridge]:https://help.shopify.com/en/api/embedded-apps/app-bridge
|