shopify_app 7.2.0 → 17.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.babelrc +5 -0
- data/.github/CODEOWNERS +1 -0
- data/.github/ISSUE_TEMPLATE/bug-report.md +63 -0
- data/.github/ISSUE_TEMPLATE/config.yml +1 -0
- data/.github/ISSUE_TEMPLATE/feature-request.md +33 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +22 -0
- data/.github/probots.yml +2 -0
- data/.github/workflows/build.yml +38 -0
- data/.github/workflows/release.yml +24 -0
- data/.github/workflows/rubocop.yml +22 -0
- data/.gitignore +4 -1
- data/.nvmrc +1 -0
- data/.rubocop.yml +18 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +465 -0
- data/CONTRIBUTING.md +76 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +256 -0
- data/README.md +73 -288
- data/Rakefile +1 -0
- data/SECURITY.md +59 -0
- data/app/assets/images/storage_access.svg +1 -0
- data/app/assets/javascripts/shopify_app/enable_cookies.js +3 -0
- data/app/assets/javascripts/shopify_app/itp_helper.js +40 -0
- data/app/assets/javascripts/shopify_app/partition_cookies.js +8 -0
- data/app/assets/javascripts/shopify_app/redirect.js +33 -0
- data/app/assets/javascripts/shopify_app/request_storage_access.js +3 -0
- data/app/assets/javascripts/shopify_app/storage_access.js +154 -0
- data/app/assets/javascripts/shopify_app/storage_access_redirect.js +17 -0
- data/app/assets/javascripts/shopify_app/top_level.js +2 -0
- data/app/assets/javascripts/shopify_app/top_level_interaction.js +11 -0
- data/app/controllers/concerns/shopify_app/authenticated.rb +16 -0
- data/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb +26 -0
- data/app/controllers/concerns/shopify_app/require_known_shop.rb +39 -0
- data/app/controllers/concerns/shopify_app/shop_access_scopes_verification.rb +32 -0
- data/app/controllers/shopify_app/authenticated_controller.rb +5 -5
- data/app/controllers/shopify_app/callback_controller.rb +196 -0
- data/app/controllers/shopify_app/extension_verification_controller.rb +15 -0
- data/app/controllers/shopify_app/sessions_controller.rb +190 -2
- data/app/controllers/shopify_app/webhooks_controller.rb +16 -7
- data/app/views/shopify_app/partials/_button_styles.html.erb +109 -0
- data/app/views/shopify_app/partials/_card_styles.html.erb +33 -0
- data/app/views/shopify_app/partials/_empty_state_styles.html.erb +98 -0
- data/app/views/shopify_app/partials/_form_styles.html.erb +56 -0
- data/app/views/shopify_app/partials/_layout_styles.html.erb +182 -0
- data/app/views/shopify_app/partials/_typography_styles.html.erb +35 -0
- data/app/views/shopify_app/sessions/enable_cookies.html.erb +70 -0
- data/app/views/shopify_app/sessions/new.html.erb +39 -83
- data/app/views/shopify_app/sessions/request_storage_access.html.erb +68 -0
- data/app/views/shopify_app/sessions/top_level_interaction.html.erb +63 -0
- data/app/views/shopify_app/shared/redirect.html.erb +23 -0
- data/config/locales/cs.yml +23 -0
- data/config/locales/da.yml +20 -0
- data/config/locales/de.yml +22 -0
- data/config/locales/en.yml +12 -1
- data/config/locales/es.yml +21 -3
- data/config/locales/fi.yml +20 -0
- data/config/locales/fr.yml +23 -0
- data/config/locales/hi.yml +23 -0
- data/config/locales/it.yml +21 -0
- data/config/locales/ja.yml +17 -0
- 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 +21 -0
- data/config/locales/pl.yml +21 -0
- data/config/locales/pt-BR.yml +21 -0
- 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/vi.yml +22 -0
- data/config/locales/zh-CN.yml +16 -0
- data/config/locales/zh-TW.yml +16 -0
- data/config/routes.rb +12 -1
- data/docs/Quickstart.md +31 -0
- data/docs/Releasing.md +21 -0
- data/docs/Troubleshooting.md +16 -0
- data/docs/Upgrading.md +110 -0
- data/docs/shopify_app/authentication.md +124 -0
- data/docs/shopify_app/engine.md +82 -0
- data/docs/shopify_app/generators.md +127 -0
- data/docs/shopify_app/handling-access-scopes-changes.md +8 -0
- data/docs/shopify_app/script-tags.md +28 -0
- data/docs/shopify_app/session-repository.md +88 -0
- data/docs/shopify_app/testing.md +38 -0
- data/docs/shopify_app/webhooks.md +72 -0
- data/karma.conf.js +44 -0
- data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +47 -0
- data/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb +11 -0
- data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +40 -0
- data/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +62 -0
- 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/app_proxy_controller/templates/index.html.erb +2 -2
- data/lib/generators/shopify_app/authenticated_controller/authenticated_controller_generator.rb +15 -0
- data/lib/generators/shopify_app/authenticated_controller/templates/authenticated_controller.rb +5 -0
- data/lib/generators/shopify_app/controllers/controllers_generator.rb +2 -1
- data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +31 -9
- data/lib/generators/shopify_app/home_controller/templates/home_controller.rb +6 -1
- data/lib/generators/shopify_app/home_controller/templates/index.html.erb +70 -6
- data/lib/generators/shopify_app/home_controller/templates/unauthenticated_home_controller.rb +11 -0
- data/lib/generators/shopify_app/install/install_generator.rb +78 -27
- data/lib/generators/shopify_app/install/templates/_flash_messages.html.erb +1 -13
- data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +12 -11
- data/lib/generators/shopify_app/install/templates/flash_messages.js +24 -0
- data/lib/generators/shopify_app/install/templates/omniauth.rb +3 -1
- data/lib/generators/shopify_app/install/templates/session_store.rb +4 -0
- data/lib/generators/shopify_app/install/templates/shopify_app.js +15 -0
- data/lib/generators/shopify_app/install/templates/shopify_app.rb.tt +25 -0
- data/lib/generators/shopify_app/install/templates/shopify_app_index.js +2 -0
- data/lib/generators/shopify_app/install/templates/shopify_provider.rb.tt +8 -0
- data/lib/generators/shopify_app/install/templates/user_agent.rb +6 -0
- 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/rotate_shopify_token_job/rotate_shopify_token_job_generator.rb +16 -0
- data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token.rake +17 -0
- data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token_job.rb +42 -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 +42 -14
- data/lib/generators/shopify_app/shop_model/templates/db/migrate/add_shop_access_scopes_column.erb +5 -0
- data/lib/generators/shopify_app/shop_model/templates/db/migrate/{create_shops.rb → create_shops.erb} +1 -1
- data/lib/generators/shopify_app/shop_model/templates/shop.rb +6 -2
- data/lib/generators/shopify_app/shopify_app_generator.rb +5 -3
- data/lib/generators/shopify_app/user_model/templates/db/migrate/add_user_access_scopes_column.erb +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 +8 -0
- data/lib/generators/shopify_app/user_model/templates/users.yml +4 -0
- data/lib/generators/shopify_app/user_model/user_model_generator.rb +70 -0
- data/lib/generators/shopify_app/views/views_generator.rb +2 -1
- data/lib/shopify_app/access_scopes/noop_strategy.rb +13 -0
- data/lib/shopify_app/access_scopes/shop_strategy.rb +24 -0
- data/lib/shopify_app/access_scopes/user_strategy.rb +41 -0
- data/lib/shopify_app/configuration.rb +69 -5
- data/lib/shopify_app/{app_proxy_verification.rb → controller_concerns/app_proxy_verification.rb} +4 -9
- data/lib/shopify_app/controller_concerns/csrf_protection.rb +15 -0
- data/lib/shopify_app/controller_concerns/embedded_app.rb +20 -0
- data/lib/shopify_app/controller_concerns/itp.rb +45 -0
- data/lib/shopify_app/controller_concerns/localization.rb +23 -0
- data/lib/shopify_app/controller_concerns/login_protection.rb +244 -0
- data/lib/shopify_app/controller_concerns/payload_verification.rb +24 -0
- data/lib/shopify_app/controller_concerns/webhook_verification.rb +23 -0
- data/lib/shopify_app/engine.rb +40 -0
- data/lib/shopify_app/jobs/scripttags_manager_job.rb +16 -0
- data/lib/shopify_app/{webhooks_manager_job.rb → jobs/webhooks_manager_job.rb} +3 -2
- data/lib/shopify_app/{scripttags_manager.rb → managers/scripttags_manager.rb} +25 -8
- data/lib/shopify_app/{webhooks_manager.rb → managers/webhooks_manager.rb} +6 -5
- data/lib/shopify_app/middleware/jwt_middleware.rb +42 -0
- data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +34 -0
- data/lib/shopify_app/omniauth/omniauth_configuration.rb +64 -0
- data/lib/shopify_app/session/in_memory_session_store.rb +31 -0
- data/lib/shopify_app/session/in_memory_shop_session_store.rb +16 -0
- data/lib/shopify_app/session/in_memory_user_session_store.rb +16 -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 +56 -0
- data/lib/shopify_app/session/session_storage.rb +20 -0
- data/lib/shopify_app/session/shop_session_storage.rb +42 -0
- data/lib/shopify_app/session/shop_session_storage_with_scopes.rb +58 -0
- data/lib/shopify_app/session/user_session_storage.rb +42 -0
- data/lib/shopify_app/session/user_session_storage_with_scopes.rb +58 -0
- 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 +24 -4
- data/lib/shopify_app/version.rb +2 -1
- data/lib/shopify_app.rb +65 -24
- data/package.json +27 -0
- data/service.yml +7 -0
- data/shipit.rubygems.yml +3 -0
- data/shopify_app.gemspec +20 -9
- data/translation.yml +7 -0
- data/webpack.config.js +24 -0
- data/yarn.lock +5215 -0
- metadata +274 -43
- data/.travis.yml +0 -17
- data/Gemfile.rails50 +0 -5
- data/Gemfile.ruby22 +0 -6
- data/Gemfile.ruby22.rails50 +0 -9
- data/ISSUE_TEMPLATE.md +0 -14
- data/QUICKSTART.md +0 -72
- data/RELEASING +0 -13
- data/lib/generators/shopify_app/home_controller/templates/shopify_app_ready_script.html.erb +0 -11
- data/lib/generators/shopify_app/install/templates/shopify_app.rb +0 -9
- data/lib/generators/shopify_app/install/templates/shopify_provider.rb +0 -4
- data/lib/generators/shopify_app/install/templates/shopify_session_repository.rb +0 -23
- data/lib/generators/shopify_app/shop_model/templates/shopify_session_repository.rb +0 -7
- data/lib/shopify_app/in_memory_session_store.rb +0 -25
- data/lib/shopify_app/login_protection.rb +0 -103
- data/lib/shopify_app/scripttags_manager_job.rb +0 -15
- data/lib/shopify_app/session_storage.rb +0 -23
- data/lib/shopify_app/sessions_concern.rb +0 -101
- data/lib/shopify_app/shop.rb +0 -15
- data/lib/shopify_app/shopify_session_repository.rb +0 -34
- data/lib/shopify_app/webhook_verification.rb +0 -39
@@ -0,0 +1,124 @@
|
|
1
|
+
# Authentication
|
2
|
+
|
3
|
+
The Shopify App gem implements [OAuth 2.0](https://shopify.dev/tutorials/authenticate-with-oauth) to get [access tokens](https://shopify.dev/concepts/about-apis/authentication#api-access-modes). These are used to authenticate requests made by the app to the Shopify API.
|
4
|
+
|
5
|
+
By default, the gem generates an embedded app frontend that uses [Shopify App Bridge](https://shopify.dev/tools/app-bridge) to fetch [session tokens](https://shopify.dev/concepts/apps/building-embedded-apps-using-session-tokens). Session tokens are used by the embedded app to make authenticated requests to the app backend.
|
6
|
+
|
7
|
+
See [*Authenticate an embedded app using session tokens*](https://shopify.dev/tutorials/authenticate-your-app-using-session-tokens) to learn more.
|
8
|
+
|
9
|
+
> ⚠️ Be sure you understand the differences between the types of authentication schemes before reading this guide.
|
10
|
+
|
11
|
+
#### Table of contents
|
12
|
+
|
13
|
+
[OAuth callback](#oauth-callback)
|
14
|
+
|
15
|
+
[Run jobs after the OAuth flow](#run-jobs-after-the-oauth-flow)
|
16
|
+
|
17
|
+
[Rotate API credentials](#rotate-api-credentials)
|
18
|
+
|
19
|
+
[Available authentication mixins](#available-authentication-mixins)
|
20
|
+
* [`ShopifyApp::Authenticated`](#shopifyappauthenticated)
|
21
|
+
* [`ShopifyApp::EnsureAuthenticatedLinks`](#shopifyappensureauthenticatedlinks)
|
22
|
+
|
23
|
+
## OAuth callback
|
24
|
+
|
25
|
+
>️ **Note:** In Shopify App version 8.4.0, we have extracted the callback logic in its own controller. If you are upgrading from a version older than 8.4.0 the callback action and related helper methods were defined in `ShopifyApp::SessionsController` ==> you will have to extend `ShopifyApp::CallbackController` instead and port your logic to the new controller.
|
26
|
+
|
27
|
+
Upon completing the OAuth flow, Shopify calls the app at the `callback_path`. 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:
|
28
|
+
* Logging into the shop and resetting the session
|
29
|
+
* [Installing Webhooks](/docs/shopify_app/webhooks.md)
|
30
|
+
* [Setting Scripttags](/docs/shopify_app/script-tags.md)
|
31
|
+
* [Run jobs after the OAuth flow](#run-jobs-after-the-oauth-flow)
|
32
|
+
* Redirecting to the return address
|
33
|
+
|
34
|
+
## Run jobs after the OAuth flow
|
35
|
+
|
36
|
+
See [`ShopifyApp::AfterAuthenticateJob`](/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb).
|
37
|
+
|
38
|
+
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:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
ShopifyApp.configure do |config|
|
42
|
+
config.after_authenticate_job = { job: "Shopify::AfterAuthenticateJob" }
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
The job can be configured as either a class or a class name string.
|
47
|
+
|
48
|
+
If you need the job to run synchronously add the `inline` flag:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
ShopifyApp.configure do |config|
|
52
|
+
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
We've also provided a generator which creates a skeleton job and updates the initializer for you:
|
57
|
+
|
58
|
+
```
|
59
|
+
bin/rails g shopify_app:add_after_authenticate_job
|
60
|
+
```
|
61
|
+
|
62
|
+
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.
|
63
|
+
|
64
|
+
## Rotate API credentials
|
65
|
+
|
66
|
+
If your Shopify secret key is leaked, you can use the RotateShopifyTokenJob to perform [API Credential Rotation](https://help.shopify.com/en/api/getting-started/authentication/oauth/api-credential-rotation).
|
67
|
+
|
68
|
+
Before running the job, you'll need to generate a new secret key from your Shopify Partner dashboard, and update the `/config/initializers/shopify_app.rb` to hold your new and old secret keys:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
config.secret = Rails.application.secrets.shopify_secret
|
72
|
+
config.old_secret = Rails.application.secrets.old_shopify_secret
|
73
|
+
```
|
74
|
+
|
75
|
+
We've provided a generator which creates the job and an example rake task:
|
76
|
+
|
77
|
+
```sh
|
78
|
+
bin/rails g shopify_app:rotate_shopify_token_job
|
79
|
+
```
|
80
|
+
|
81
|
+
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.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
strategy.options[:old_client_secret] = ShopifyApp.configuration.old_secret
|
85
|
+
```
|
86
|
+
|
87
|
+
> **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`:
|
88
|
+
|
89
|
+
## Available authentication mixins
|
90
|
+
|
91
|
+
### `ShopifyApp::Authenticated`
|
92
|
+
|
93
|
+
The engine provides a [`ShopifyApp::Authenticated`](/app/controllers/concerns/shopify_app/authenticated.rb) 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.
|
94
|
+
|
95
|
+
*Example:*
|
96
|
+
|
97
|
+
```rb
|
98
|
+
class AuthenticatedController < ApplicationController
|
99
|
+
include ShopifyApp::Authenticated
|
100
|
+
end
|
101
|
+
|
102
|
+
class ApiController < AuthenticatedController
|
103
|
+
# Actions in this controller are protected
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
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`.
|
108
|
+
|
109
|
+
### `ShopifyApp::EnsureAuthenticatedLinks`
|
110
|
+
|
111
|
+
The [`ShopifyApp::EnsureAuthenticatedLinks`](/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb) concern helps authenticate users that access protected pages of your app directly.
|
112
|
+
|
113
|
+
Include this concern in your app's `AuthenticatedController` if your app uses session tokens with [Turbolinks](https://github.com/turbolinks/turbolinks). It adds a `before_action` filter that detects whether a session token is present or not. If a session token is not found, the user is redirected to your app's splash page path (`root_path`) along with `return_to` and `shop` parameters.
|
114
|
+
|
115
|
+
*Example:*
|
116
|
+
|
117
|
+
```rb
|
118
|
+
class AuthenticatedController < ApplicationController
|
119
|
+
include ShopifyApp::EnsureAuthenticatedLinks
|
120
|
+
include ShopifyApp::Authenticated
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
See [Authenticate server-side rendered embedded apps using Rails and Turbolinks](https://shopify.dev/tutorials/authenticate-server-side-rendered-embedded-apps-using-rails-and-turbolinks) for more information.
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Engine
|
2
|
+
|
3
|
+
#### Table of contents
|
4
|
+
|
5
|
+
[Customize the app login URL](#customize-the-app-login-url)
|
6
|
+
|
7
|
+
[Mount the Shopify App engine at nested routes](#mount-the-shopify-app-engine-at-nested-routes)
|
8
|
+
|
9
|
+
[Verify HTTP requests sent via an app proxy](#verify-http-requests-sent-via-an-app-proxy)
|
10
|
+
* [Recommended usage of `ShopifyApp::AppProxyVerification`](#recommended-usage-of-shopifyappappproxyverification)
|
11
|
+
|
12
|
+
## Customize the app login URL
|
13
|
+
|
14
|
+
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.:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
ShopifyApp.configure do |config|
|
18
|
+
config.login_url = 'https://my.domain.com/nested/login'
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
## Mount the Shopify App engine at nested routes
|
23
|
+
|
24
|
+
The engine may also be mounted at a nested route, for example:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
mount ShopifyApp::Engine, at: '/nested'
|
28
|
+
```
|
29
|
+
|
30
|
+
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.:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
ShopifyApp.configure do |config|
|
34
|
+
config.root_url = '/nested'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
then update the omniauth initializer to include a custom `callback_path` e.g.:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
provider :shopify,
|
42
|
+
ShopifyApp.configuration.api_key,
|
43
|
+
ShopifyApp.configuration.secret,
|
44
|
+
scope: ShopifyApp.configuration.scope,
|
45
|
+
callback_path: '/nested/auth/shopify/callback'
|
46
|
+
```
|
47
|
+
|
48
|
+
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:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# config/routes.rb
|
52
|
+
Rails.application.routes.draw do
|
53
|
+
root :to => 'something_else#index'
|
54
|
+
get "/nested", to: "home#index"
|
55
|
+
mount ShopifyApp::Engine, at: '/nested'
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
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.
|
60
|
+
|
61
|
+
## Verify HTTP requests sent via an app proxy
|
62
|
+
|
63
|
+
See [`ShopifyApp::AppProxyVerification`](/lib/shopify_app/controller_concerns/app_proxy_verification.rb).
|
64
|
+
|
65
|
+
The engine provides a mixin for verifying incoming HTTP requests sent via an App Proxy. Any controller that `include`s `ShopifyApp::AppProxyVerification` will verify that each request has a valid `signature` query parameter that is calculated using the other query parameters and the app's shared secret.
|
66
|
+
|
67
|
+
### Recommended usage of `ShopifyApp::AppProxyVerification`
|
68
|
+
|
69
|
+
The App Proxy Controller Generator automatically adds the mixin to the generated app_proxy_controller.rb
|
70
|
+
Additional controllers for resources within the App_Proxy namespace, will need to include the mixin like so:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# app/controllers/app_proxy/reviews_controller.rb
|
74
|
+
class ReviewsController < ApplicationController
|
75
|
+
include ShopifyApp::AppProxyVerification
|
76
|
+
# ...
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
Create your app proxy URL in the [Shopify Partners dashboard](https://partners.shopify.com/organizations), making sure to point it to `https://your_app_website.com/app_proxy`.
|
81
|
+
|
82
|
+
![Creating an App Proxy](/images/app-proxy-screenshot.png)
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# Generators
|
2
|
+
|
3
|
+
> Listed below are the generators currently offered by the Shopify App gem. To learn more about how this gem creates an embedded app, start with the [default Shopify App generator](#-environment-rails-generate-shopify_app).
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
#### `$ [environment] rails generate shopify_app`
|
8
|
+
|
9
|
+
The default generator will run the [`install`](#-rails-generate-shopify_appinstall-flags), [`shop_model`](#-rails-generate-shopify_appshop_model), [`authenticated_controller`](#-rails-generate-shopify_appauthenticated_controller), and [`home_controller`](#-rails-generate-shopify_apphome_controller-flags) generators. This is the recommended way to start a new app from scratch.
|
10
|
+
|
11
|
+
##### Environment
|
12
|
+
|
13
|
+
###### `SHOPIFY_APP_DISABLE_WEBPACKER`
|
14
|
+
|
15
|
+
**[Optional]** Specify this environment variable if your app uses sprockets with Rails 6 or to generate a Shopify App without webpacker.
|
16
|
+
|
17
|
+
*Example:*
|
18
|
+
|
19
|
+
Run:
|
20
|
+
|
21
|
+
```terminal
|
22
|
+
$ SHOPIFY_APP_DISABLE_WEBPACKER=1 rails generate shopify_app
|
23
|
+
```
|
24
|
+
|
25
|
+
Add the following code to your ShopifyApp configuration block:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
ShopifyApp.configure do |config|
|
29
|
+
config.disable_webpacker = true
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
---
|
34
|
+
|
35
|
+
#### `$ rails generate shopify_app:install [flags]`
|
36
|
+
|
37
|
+
This generator adds ShopifyApp and the required initializers to the host Rails application. You can update any of these settings later.
|
38
|
+
|
39
|
+
##### Flags
|
40
|
+
|
41
|
+
###### `--application_name`
|
42
|
+
|
43
|
+
The name of your app. The flag can be supplied with or without double-quotes.
|
44
|
+
|
45
|
+
*Example:* `--application_name "My Shopify App"`
|
46
|
+
|
47
|
+
###### `--scope`
|
48
|
+
|
49
|
+
The [OAuth access scope(s)](https://shopify.dev/docs/admin-api/access-scopes) required by your app. Delimit multiple access scopes using a comma-space. The flag can be supplied with or without double-quotes.
|
50
|
+
|
51
|
+
*Example:* `--scope read_products, write_orders`
|
52
|
+
|
53
|
+
*Example:* `--scope "read_products, write_orders"`
|
54
|
+
|
55
|
+
###### `--embedded`
|
56
|
+
|
57
|
+
Specify whether the app is an embedded app. Apps are embedded by default.
|
58
|
+
|
59
|
+
*Example:* `--embedded false`
|
60
|
+
|
61
|
+
###### `--with-cookie-authentication`
|
62
|
+
|
63
|
+
**[Not recommended]** Specify whether the app uses cookies to authenticate. By default, the app is configured to use [session tokens](https://shopify.dev/concepts/apps/building-embedded-apps-using-session-tokens).
|
64
|
+
|
65
|
+
*Example:* `--with-cookie-authentication true`
|
66
|
+
|
67
|
+
---
|
68
|
+
|
69
|
+
#### `$ rails generate shopify_app:shop_model`
|
70
|
+
|
71
|
+
This generator creates a `Shop` model and a migration to store shop installation records. See [*Shop-based token strategy*](/docs/shopify_app/session-repository.md#shop-based-token-storage) to learn more.
|
72
|
+
|
73
|
+
---
|
74
|
+
|
75
|
+
#### `$ rails generate shopify_app:user_model`
|
76
|
+
|
77
|
+
This generator creates a `User` model and a migration to store user records. See [*User-based token strategy*](/docs/shopify_app/session-repository.md#user-based-token-storage) to learn more.
|
78
|
+
|
79
|
+
---
|
80
|
+
|
81
|
+
#### `$ rails generate shopify_app:authenticated_controller`
|
82
|
+
|
83
|
+
This generator creates a sample authenticated controller. By default, inheriting from this controller protects your app controllers using session tokens. See [*Authentication*](/docs/shopify_app/authentication.md) to learn more.
|
84
|
+
|
85
|
+
---
|
86
|
+
|
87
|
+
#### `$ rails generate shopify_app:home_controller [flags]`
|
88
|
+
|
89
|
+
This generator creates a sample home controller with a view that displays a shop's products. This generator also runs the [`products_controller`](#-rails-generate-shopify_appproducts_controller) generator.
|
90
|
+
|
91
|
+
##### Flags
|
92
|
+
|
93
|
+
###### `--with-cookie-authentication`
|
94
|
+
|
95
|
+
**[Not recommended]** This flag generates an authenticated home controller. Use this flag only if your app uses cookies to authenticate. By default, the home controller is unauthenticated.
|
96
|
+
|
97
|
+
---
|
98
|
+
|
99
|
+
#### `$ rails generate shopify_app:products_controller`
|
100
|
+
|
101
|
+
This generator creates a sample products API controller to fetch products using the Shopify REST API.
|
102
|
+
|
103
|
+
---
|
104
|
+
|
105
|
+
#### `$ rails generate shopify_app:add_after_authenticate_job`
|
106
|
+
|
107
|
+
**[Optional]** This generator creates a skeleton job that runs after the OAuth authorization flow. See [*Run jobs after the OAuth flow*](/docs/shopify_app/authentication.md#run-jobs-after-the-oauth-flow) for more information.
|
108
|
+
|
109
|
+
---
|
110
|
+
|
111
|
+
#### `$ rails generate shopify_app:app_proxy_controller`
|
112
|
+
|
113
|
+
**[Optional]** This generator creates the app proxy controller to handle proxy requests to the app from your shop storefront. It also modifies 'config/routes.rb' with a namespace route and creates a sample view that displays current shop information using the LiquidAPI. See [*Verify HTTP requests sent via an app proxy*](/docs/shopify_app/engine.md#verify-http-requests-sent-via-an-app-proxy) for more information.
|
114
|
+
|
115
|
+
---
|
116
|
+
|
117
|
+
#### `$ rails generate shopify_app:marketing_activity_extension`
|
118
|
+
|
119
|
+
**[Optional]** This generator creates a controller with the endpoints required to build a [marketing activities extension](https://shopify.dev/docs/marketing-activities). The extension is generated with the base URL `/marketing_activities`. This URL would need to be configured in the Shopify Partners dashboard.
|
120
|
+
|
121
|
+
---
|
122
|
+
|
123
|
+
#### `$ rails generate shopify_app:controllers`
|
124
|
+
|
125
|
+
**[Optional]** This generator is for your convenience. Run this generator if you would like to override code that is part of the Shopify App Rails engine.
|
126
|
+
|
127
|
+
*Example:* The Shopify App Rails engine provides a sample [`SessionsController`](/app/controllers/shopify_app/sessions_controller.rb). Running this generator copies this controller to your app so you can begin extending it. Routes and views follow the same pattern.
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Handling changes in access scopes
|
2
|
+
The Shopify App gem provides handling changes to scopes for both shop/offline and user/online tokens. To enable your app to login via OAuth on scope changes, you can set the following configuration flag:
|
3
|
+
```ruby
|
4
|
+
ShopifyApp.configuration.reauth_on_access_scope_changes = true
|
5
|
+
```
|
6
|
+
|
7
|
+
## ShopAccessScopesVerification
|
8
|
+
The `ShopifyApp::ShopAccessScopesVerification` concern helps merchants grant new access scopes requested by the app. The concern compares the current access scopes granted by the shop and compares them with the scopes requested by the app. If there is a mismatch in configuration, the merchant is redirected to login via OAuth and grant the net new scopes.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# ScriptTags
|
2
|
+
|
3
|
+
#### Table of contents
|
4
|
+
|
5
|
+
[Manage ScriptTags using the Shopify App initializer](#manage-scripttags-using-the-shopify-app-initializer)
|
6
|
+
|
7
|
+
## Manage ScriptTags using the Shopify App initializer
|
8
|
+
|
9
|
+
As with webhooks, ShopifyApp can manage your app's [ScriptTags](https://shopify-dev-staging.shopifycloud.com/docs/admin-api/graphql/reference/online-store/scripttag) for you by setting which scripttags you require in the initializer:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
ShopifyApp.configure do |config|
|
13
|
+
config.scripttags = [
|
14
|
+
{event:'onload', src: 'https://my-shopifyapp.herokuapp.com/fancy.js'},
|
15
|
+
{event:'onload', src: ->(domain) { dynamic_tag_url(domain) } }
|
16
|
+
]
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
You also need to have write_script_tags permission in the config scope in order to add script tags automatically:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
config.scope = '... , write_script_tags'
|
24
|
+
```
|
25
|
+
|
26
|
+
Scripttags are created in the same way as the [Webhooks](/docs/shopify_app/webhooks.md), with a background job which will create the required scripttags.
|
27
|
+
|
28
|
+
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.
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# Session repository
|
2
|
+
|
3
|
+
#### Table of contents
|
4
|
+
|
5
|
+
[`ShopifyApp::SessionRepository`](#shopifyappsessionrepository)
|
6
|
+
* [Shop-based token storage](#shop-based-token-storage)
|
7
|
+
* [User-based token storage](#user-based-token-storage)
|
8
|
+
|
9
|
+
[Access scopes](#access-scopes)
|
10
|
+
* [`ShopifyApp::ShopSessionStorageWithScopes`](#shopifyappshopsessionstoragewithscopes)
|
11
|
+
* [``ShopifyApp::UserSessionStorageWithScopes``](#shopifyappusersessionstoragewithscopes)
|
12
|
+
|
13
|
+
[Migrating from shop-based to user-based token strategy](#migrating-from-shop-based-to-user-based-token-strategy)
|
14
|
+
|
15
|
+
## ShopifyApp::SessionRepository
|
16
|
+
|
17
|
+
`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.
|
18
|
+
|
19
|
+
### Shop-based token storage
|
20
|
+
|
21
|
+
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.
|
22
|
+
```sh
|
23
|
+
$ rails generate shopify_app:shop_model
|
24
|
+
```
|
25
|
+
This will generate a shop model which will be the storage for the tokens necessary for authentication.
|
26
|
+
|
27
|
+
### User-based token storage
|
28
|
+
|
29
|
+
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.
|
30
|
+
```sh
|
31
|
+
$ rails generate shopify_app:shop_model
|
32
|
+
$ rails generate shopify_app:user_model
|
33
|
+
```
|
34
|
+
This will generate a shop model and user model, which will be the storage for the tokens necessary for authentication.
|
35
|
+
|
36
|
+
The current Shopify user will be stored in the rails session at `session[:shopify_user]`
|
37
|
+
|
38
|
+
Read more about Online vs. Offline access [here](https://help.shopify.com/api/getting-started/authentication/oauth).
|
39
|
+
|
40
|
+
## Access scopes
|
41
|
+
|
42
|
+
If you want to customize how access scopes are stored for shops and users, you can implement the `access_scopes` getters and setters in the models that include `ShopifyApp::ShopSessionStorageWithScopes` and `ShopifyApp::UserSessionStorageWithScopes` as shown:
|
43
|
+
|
44
|
+
### `ShopifyApp::ShopSessionStorageWithScopes`
|
45
|
+
```ruby
|
46
|
+
class Shop < ActiveRecord::Base
|
47
|
+
include ShopifyApp::ShopSessionStorageWithScopes
|
48
|
+
|
49
|
+
def access_scopes=(scopes)
|
50
|
+
# Store access scopes
|
51
|
+
end
|
52
|
+
def access_scopes
|
53
|
+
# Find access scopes
|
54
|
+
end
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
### `ShopifyApp::UserSessionStorageWithScopes`
|
59
|
+
```ruby
|
60
|
+
class User < ActiveRecord::Base
|
61
|
+
include ShopifyApp::UserSessionStorageWithScopes
|
62
|
+
|
63
|
+
def access_scopes=(scopes)
|
64
|
+
# Store access scopes
|
65
|
+
end
|
66
|
+
def access_scopes
|
67
|
+
# Find access scopes
|
68
|
+
end
|
69
|
+
end
|
70
|
+
```
|
71
|
+
## Migrating from shop-based to user-based token strategy
|
72
|
+
|
73
|
+
1. Run the `user_model` generator as mentioned above.
|
74
|
+
2. Ensure that both your `Shop` model and `User` model includes the necessary concerns `ShopifyApp::ShopSessionStorage` and `ShopifyApp::UserSessionStorage`.
|
75
|
+
3. Make changes to 2 initializer files as shown below:
|
76
|
+
```ruby
|
77
|
+
# In the `omniauth.rb` initializer:
|
78
|
+
provider :shopify,
|
79
|
+
...
|
80
|
+
setup: lambda { |env|
|
81
|
+
configuration = ShopifyApp::OmniauthConfiguration.new(env['omniauth.strategy'], Rack::Request.new(env))
|
82
|
+
configuration.build_options
|
83
|
+
}
|
84
|
+
|
85
|
+
# In the `shopify_app.rb` initializer:
|
86
|
+
config.shop_session_repository = {YOUR_SHOP_MODEL_CLASS}
|
87
|
+
config.user_session_repository = {YOUR_USER_MODEL_CLASS}
|
88
|
+
```
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Testing
|
2
|
+
|
3
|
+
#### Table of contents
|
4
|
+
|
5
|
+
[Using test helpers inside your application](#using-test-helpers-inside-your-application)
|
6
|
+
|
7
|
+
[Testing an embedded app outside the Shopify admin](#testing-an-embedded-app-outside-the-shopify-admin)
|
8
|
+
|
9
|
+
## Using test helpers inside your application
|
10
|
+
|
11
|
+
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`.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'test_helper'
|
15
|
+
require 'action_controller'
|
16
|
+
require 'action_controller/base'
|
17
|
+
require 'shopify_app/test_helpers/webhook_verification_helper'
|
18
|
+
```
|
19
|
+
|
20
|
+
Or you can require in your `test/test_helper.rb`.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
ENV['RAILS_ENV'] ||= 'test'
|
24
|
+
require_relative '../config/environment'
|
25
|
+
require 'rails/test_help'
|
26
|
+
require 'byebug'
|
27
|
+
require 'shopify_app/test_helpers/all'
|
28
|
+
```
|
29
|
+
|
30
|
+
With `lib/shopify_app/test_helpers/all'` more tests can be added and will only need to be required in once in your library.
|
31
|
+
|
32
|
+
## Testing an embedded app outside the Shopify admin
|
33
|
+
|
34
|
+
By default, loading your embedded app will redirect to the Shopify admin, with the app view loaded in an `iframe`. If you need to load your app outside of the Shopify admin (e.g., for performance testing), you can change `forceRedirect: true` to `false` in `ShopifyApp.init` block in the `embedded_app` view. To keep the redirect on in production but off in your `development` and `test` environments, you can use:
|
35
|
+
|
36
|
+
```javascript
|
37
|
+
forceRedirect: <%= Rails.env.development? || Rails.env.test? ? 'false' : 'true' %>
|
38
|
+
```
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Webhooks
|
2
|
+
|
3
|
+
#### Table of contents
|
4
|
+
|
5
|
+
[Manage webhooks using `ShopifyApp::WebhooksManager`](#manage-webhooks-using-shopifyappwebhooksmanager)
|
6
|
+
|
7
|
+
## Manage webhooks using `ShopifyApp::WebhooksManager`
|
8
|
+
|
9
|
+
See [`ShopifyApp::WebhooksManager`](/lib/shopify_app/managers/webhooks_manager.rb)
|
10
|
+
ShopifyApp can manage your app's webhooks for you if you set which webhooks you require in the initializer:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
ShopifyApp.configure do |config|
|
14
|
+
config.webhooks = [
|
15
|
+
{topic: 'carts/update', address: 'https://example-app.com/webhooks/carts_update'}
|
16
|
+
]
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
When the [OAuth callback](/docs/shopify_app/authentication.md#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.
|
21
|
+
|
22
|
+
ShopifyApp also provides a [WebhooksController](/app/controllers/shopify_app/webhooks_controller.rb) 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).
|
23
|
+
|
24
|
+
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`):
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
ShopifyApp.configure do |config|
|
28
|
+
config.webhook_jobs_namespace = 'shopify/webhooks'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
If you are only interested in particular fields, you can optionally filter the data sent by Shopify by specifying the `fields` parameter in `config/webhooks`. Note that you will still receive a webhook request from Shopify every time the resource is updated, but only the specified fields will be sent.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
ShopifyApp.configure do |config|
|
36
|
+
config.webhooks = [
|
37
|
+
{topic: 'products/update', address: 'https://example-app.com/webhooks/products_update', fields: ['title', 'vendor']}
|
38
|
+
]
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
If you'd rather implement your own controller then you'll want to use the [`ShopifyApp::WebhookVerification`](/lib/shopify_app/controller_concerns/webhook_verification.rb) module to verify your webhooks, example:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
class CustomWebhooksController < ApplicationController
|
46
|
+
include ShopifyApp::WebhookVerification
|
47
|
+
|
48
|
+
def carts_update
|
49
|
+
params.permit!
|
50
|
+
SomeJob.perform_later(shop_domain: shop_domain, webhook: webhook_params.to_h)
|
51
|
+
head :no_content
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def webhook_params
|
57
|
+
params.except(:controller, :action, :type)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
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.
|
63
|
+
|
64
|
+
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.
|
65
|
+
|
66
|
+
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.
|
67
|
+
|
68
|
+
```
|
69
|
+
rails g shopify_app:add_webhook -t carts/update -a https://example.com/webhooks/carts_update
|
70
|
+
```
|
71
|
+
|
72
|
+
Where `-t` is the topic and `-a` is the address the webhook should be sent to.
|
data/karma.conf.js
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
const karmaReporters = ['mocha-clean'];
|
2
|
+
|
3
|
+
function isDebug(argument) {
|
4
|
+
return argument === '--debug';
|
5
|
+
}
|
6
|
+
|
7
|
+
module.exports = function(config) {
|
8
|
+
config.set({
|
9
|
+
mode: 'development',
|
10
|
+
basePath: '',
|
11
|
+
frameworks: ['mocha', 'chai-sinon'],
|
12
|
+
files: [
|
13
|
+
'app/assets/javascripts/**/*.js',
|
14
|
+
'test/javascripts/**/*test.js',
|
15
|
+
],
|
16
|
+
exclude: [
|
17
|
+
// Exclude JS files that create 'DOMContentLoaded' event listeners
|
18
|
+
'app/assets/javascripts/**/redirect.js',
|
19
|
+
'app/assets/javascripts/**/storage_access_redirect.js',
|
20
|
+
'app/assets/javascripts/**/top_level_interaction.js',
|
21
|
+
'app/assets/javascripts/**/partition_cookies.js',
|
22
|
+
],
|
23
|
+
mochaReporter: {
|
24
|
+
output: 'autowatch',
|
25
|
+
},
|
26
|
+
preprocessors: {
|
27
|
+
'test/javascripts/**/*test.js': ['webpack'],
|
28
|
+
},
|
29
|
+
webpack: {},
|
30
|
+
reporters: karmaReporters,
|
31
|
+
port: 9876,
|
32
|
+
colors: true,
|
33
|
+
logLevel: config.LOG_WARN,
|
34
|
+
autoWatch: false,
|
35
|
+
browsers: ['ChromeHeadless'],
|
36
|
+
singleRun: true,
|
37
|
+
client: {
|
38
|
+
mocha: {
|
39
|
+
ui: 'tdd',
|
40
|
+
grep: config.grep,
|
41
|
+
},
|
42
|
+
},
|
43
|
+
});
|
44
|
+
};
|
data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/generators/base'
|
3
|
+
|
4
|
+
module ShopifyApp
|
5
|
+
module Generators
|
6
|
+
class AddAfterAuthenticateJobGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
hook_for :test_framework, as: :job, in: :rails do |instance, generator|
|
10
|
+
instance.invoke(generator, [instance.send(:job_file_name)])
|
11
|
+
end
|
12
|
+
|
13
|
+
def init_after_authenticate_config
|
14
|
+
initializer = load_initializer
|
15
|
+
|
16
|
+
after_authenticate_job_config =
|
17
|
+
" config.after_authenticate_job = "\
|
18
|
+
"{ job: \"Shopify::AfterAuthenticateJob\", inline: false }\n"
|
19
|
+
|
20
|
+
inject_into_file(
|
21
|
+
'config/initializers/shopify_app.rb',
|
22
|
+
after_authenticate_job_config,
|
23
|
+
before: 'end'
|
24
|
+
)
|
25
|
+
|
26
|
+
unless initializer.include?(after_authenticate_job_config)
|
27
|
+
shell.say("Error adding after_authenticate_job to config. Add this line manually: "\
|
28
|
+
"#{after_authenticate_job_config}", :red)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_after_authenticate_job
|
33
|
+
template('after_authenticate_job.rb', "app/jobs/#{job_file_name}_job.rb")
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def load_initializer
|
39
|
+
File.read(File.join(destination_root, 'config/initializers/shopify_app.rb'))
|
40
|
+
end
|
41
|
+
|
42
|
+
def job_file_name
|
43
|
+
'shopify/after_authenticate'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|