shopify_app 12.0.0 → 17.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -0
  3. data/.github/ISSUE_TEMPLATE/bug-report.md +63 -0
  4. data/.github/ISSUE_TEMPLATE/config.yml +1 -0
  5. data/.github/ISSUE_TEMPLATE/feature-request.md +33 -0
  6. data/.github/PULL_REQUEST_TEMPLATE.md +22 -0
  7. data/.github/workflows/build.yml +41 -0
  8. data/.github/workflows/release.yml +24 -0
  9. data/.github/workflows/rubocop.yml +22 -0
  10. data/.gitignore +0 -2
  11. data/.rubocop.yml +14 -6
  12. data/CHANGELOG.md +180 -0
  13. data/CONTRIBUTING.md +76 -0
  14. data/Gemfile +5 -0
  15. data/Gemfile.lock +257 -0
  16. data/README.md +72 -487
  17. data/Rakefile +1 -0
  18. data/SECURITY.md +59 -0
  19. data/app/assets/images/storage_access.svg +1 -2
  20. data/app/assets/javascripts/shopify_app/itp_helper.js +6 -6
  21. data/app/assets/javascripts/shopify_app/storage_access.js +37 -7
  22. data/app/assets/javascripts/shopify_app/top_level_interaction.js +1 -1
  23. data/app/controllers/concerns/shopify_app/authenticated.rb +2 -1
  24. data/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb +26 -0
  25. data/app/controllers/concerns/shopify_app/require_known_shop.rb +39 -0
  26. data/app/controllers/concerns/shopify_app/shop_access_scopes_verification.rb +32 -0
  27. data/app/controllers/shopify_app/authenticated_controller.rb +1 -0
  28. data/app/controllers/shopify_app/callback_controller.rb +113 -23
  29. data/app/controllers/shopify_app/extension_verification_controller.rb +2 -7
  30. data/app/controllers/shopify_app/sessions_controller.rb +62 -14
  31. data/app/controllers/shopify_app/webhooks_controller.rb +6 -5
  32. data/app/views/shopify_app/partials/_button_styles.html.erb +41 -36
  33. data/app/views/shopify_app/partials/_card_styles.html.erb +3 -3
  34. data/app/views/shopify_app/partials/_empty_state_styles.html.erb +28 -59
  35. data/app/views/shopify_app/partials/_form_styles.html.erb +56 -0
  36. data/app/views/shopify_app/partials/_layout_styles.html.erb +16 -1
  37. data/app/views/shopify_app/partials/_typography_styles.html.erb +6 -6
  38. data/app/views/shopify_app/sessions/enable_cookies.html.erb +3 -8
  39. data/app/views/shopify_app/sessions/new.html.erb +38 -110
  40. data/app/views/shopify_app/sessions/request_storage_access.html.erb +2 -2
  41. data/app/views/shopify_app/sessions/top_level_interaction.html.erb +21 -22
  42. data/config/locales/de.yml +11 -11
  43. data/config/locales/fi.yml +1 -1
  44. data/config/locales/nl.yml +8 -8
  45. data/config/locales/pt-BR.yml +1 -1
  46. data/config/locales/th.yml +4 -4
  47. data/config/locales/vi.yml +22 -0
  48. data/config/locales/zh-CN.yml +1 -1
  49. data/config/routes.rb +1 -0
  50. data/docs/Quickstart.md +15 -87
  51. data/docs/Releasing.md +18 -14
  52. data/docs/Troubleshooting.md +129 -4
  53. data/docs/Upgrading.md +126 -0
  54. data/docs/shopify_app/authentication.md +124 -0
  55. data/docs/shopify_app/engine.md +82 -0
  56. data/docs/shopify_app/generators.md +127 -0
  57. data/docs/shopify_app/handling-access-scopes-changes.md +14 -0
  58. data/docs/shopify_app/script-tags.md +28 -0
  59. data/docs/shopify_app/session-repository.md +88 -0
  60. data/docs/shopify_app/testing.md +38 -0
  61. data/docs/shopify_app/webhooks.md +72 -0
  62. data/karma.conf.js +1 -1
  63. data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +5 -3
  64. data/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb +1 -0
  65. data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +2 -1
  66. data/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +4 -8
  67. data/lib/generators/shopify_app/add_webhook/add_webhook_generator.rb +5 -4
  68. data/lib/generators/shopify_app/add_webhook/templates/{webhook_job.rb → webhook_job.rb.tt} +5 -0
  69. data/lib/generators/shopify_app/app_proxy_controller/app_proxy_controller_generator.rb +4 -3
  70. data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_controller.rb +3 -3
  71. data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_route.rb +10 -9
  72. data/lib/generators/shopify_app/authenticated_controller/authenticated_controller_generator.rb +1 -1
  73. data/lib/generators/shopify_app/controllers/controllers_generator.rb +2 -1
  74. data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +31 -3
  75. data/lib/generators/shopify_app/home_controller/templates/home_controller.rb +2 -0
  76. data/lib/generators/shopify_app/home_controller/templates/index.html.erb +66 -16
  77. data/lib/generators/shopify_app/home_controller/templates/unauthenticated_home_controller.rb +11 -0
  78. data/lib/generators/shopify_app/install/install_generator.rb +46 -11
  79. data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +1 -1
  80. data/lib/generators/shopify_app/install/templates/flash_messages.js +0 -2
  81. data/lib/generators/shopify_app/install/templates/omniauth.rb +3 -1
  82. data/lib/generators/shopify_app/install/templates/shopify_app.rb.tt +25 -0
  83. data/lib/generators/shopify_app/install/templates/shopify_provider.rb.tt +8 -0
  84. data/lib/generators/shopify_app/install/templates/user_agent.rb +2 -1
  85. data/lib/generators/shopify_app/products_controller/products_controller_generator.rb +19 -0
  86. data/lib/generators/shopify_app/products_controller/templates/products_controller.rb +8 -0
  87. data/lib/generators/shopify_app/routes/routes_generator.rb +1 -0
  88. data/lib/generators/shopify_app/routes/templates/routes.rb +10 -9
  89. data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +39 -7
  90. data/lib/generators/shopify_app/shop_model/templates/db/migrate/add_shop_access_scopes_column.erb +5 -0
  91. data/lib/generators/shopify_app/shop_model/templates/shop.rb +2 -1
  92. data/lib/generators/shopify_app/shopify_app_generator.rb +4 -3
  93. data/lib/generators/shopify_app/user_model/templates/db/migrate/add_user_access_scopes_column.erb +5 -0
  94. data/lib/generators/shopify_app/user_model/templates/user.rb +2 -1
  95. data/lib/generators/shopify_app/user_model/user_model_generator.rb +39 -7
  96. data/lib/generators/shopify_app/views/views_generator.rb +2 -1
  97. data/lib/shopify_app/access_scopes/noop_strategy.rb +13 -0
  98. data/lib/shopify_app/access_scopes/shop_strategy.rb +24 -0
  99. data/lib/shopify_app/access_scopes/user_strategy.rb +41 -0
  100. data/lib/shopify_app/configuration.rb +46 -11
  101. data/lib/shopify_app/controller_concerns/app_proxy_verification.rb +3 -3
  102. data/lib/shopify_app/controller_concerns/csrf_protection.rb +15 -0
  103. data/lib/shopify_app/controller_concerns/embedded_app.rb +3 -2
  104. data/lib/shopify_app/controller_concerns/localization.rb +1 -0
  105. data/lib/shopify_app/controller_concerns/login_protection.rb +105 -30
  106. data/lib/shopify_app/controller_concerns/payload_verification.rb +24 -0
  107. data/lib/shopify_app/controller_concerns/webhook_verification.rb +3 -18
  108. data/lib/shopify_app/engine.rb +27 -1
  109. data/lib/shopify_app/jobs/scripttags_manager_job.rb +1 -1
  110. data/lib/shopify_app/jobs/webhooks_manager_job.rb +1 -1
  111. data/lib/shopify_app/managers/scripttags_manager.rb +4 -3
  112. data/lib/shopify_app/managers/webhooks_manager.rb +4 -3
  113. data/lib/shopify_app/middleware/jwt_middleware.rb +42 -0
  114. data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +19 -45
  115. data/lib/shopify_app/omniauth/omniauth_configuration.rb +64 -0
  116. data/lib/shopify_app/session/in_memory_session_store.rb +7 -3
  117. data/lib/shopify_app/session/in_memory_shop_session_store.rb +16 -0
  118. data/lib/shopify_app/session/in_memory_user_session_store.rb +16 -0
  119. data/lib/shopify_app/session/jwt.rb +63 -0
  120. data/lib/shopify_app/session/null_user_session_store.rb +22 -0
  121. data/lib/shopify_app/session/session_repository.rb +36 -14
  122. data/lib/shopify_app/session/session_storage.rb +1 -10
  123. data/lib/shopify_app/session/shop_session_storage.rb +42 -0
  124. data/lib/shopify_app/session/shop_session_storage_with_scopes.rb +58 -0
  125. data/lib/shopify_app/session/user_session_storage.rb +42 -0
  126. data/lib/shopify_app/session/user_session_storage_with_scopes.rb +58 -0
  127. data/lib/shopify_app/test_helpers/all.rb +2 -0
  128. data/lib/shopify_app/test_helpers/webhook_verification_helper.rb +17 -0
  129. data/lib/shopify_app/utils.rb +18 -5
  130. data/lib/shopify_app/version.rb +2 -1
  131. data/lib/shopify_app.rb +24 -5
  132. data/package.json +8 -9
  133. data/shopify_app.gemspec +15 -10
  134. data/translation.yml +1 -1
  135. data/yarn.lock +2120 -2168
  136. metadata +94 -20
  137. data/.github/ISSUE_TEMPLATE.md +0 -14
  138. data/.travis.yml +0 -27
  139. data/docs/install-on-dev-shop.png +0 -0
  140. data/docs/test-your-app.png +0 -0
  141. data/lib/generators/shopify_app/install/templates/shopify_app.rb +0 -15
  142. data/lib/generators/shopify_app/install/templates/shopify_provider.rb +0 -20
  143. data/lib/shopify_app/session/storage_strategies/shop_storage_strategy.rb +0 -23
  144. data/lib/shopify_app/session/storage_strategies/user_storage_strategy.rb +0 -24
  145. data/package-lock.json +0 -7224
@@ -1,20 +1,20 @@
1
1
  ---
2
2
  nl:
3
- logged_out: u bent afgemeld
4
- could_not_log_in: Kon niet aanmelden bij Shopify-winkel
3
+ logged_out: Je bent afgemeld
4
+ could_not_log_in: Kon niet inloggen bij Shopify-winkel
5
5
  invalid_shop_url: Ongeldig winkeldomein
6
6
  enable_cookies_heading: Schakel cookies in van %{app}
7
- enable_cookies_body: U moet cookies in deze browser handmatig inschakelen om %{app}
7
+ enable_cookies_body: Je moet cookies in deze browser handmatig inschakelen om %{app}
8
8
  binnen Shopify te gebruiken.
9
- enable_cookies_footer: Met cookies kan de app u verifiëren door uw voorkeuren en
9
+ enable_cookies_footer: Met cookies kan de app je verifiëren door je voorkeuren en
10
10
  persoonlijke informatie tijdelijk op te slaan. Ze vervallen na 30 dagen.
11
11
  enable_cookies_action: Schakel cookies in
12
- top_level_interaction_heading: Uw browser moet %{app} verifiëren
13
- top_level_interaction_body: Uw browser heeft apps nodig zoals %{app} om u toegang
14
- te vragen tot cookies voordat Shopify het voor u kan openen.
12
+ top_level_interaction_heading: Je browser moet %{app} verifiëren
13
+ top_level_interaction_body: Je browser heeft apps nodig zoals %{app} om je toegang
14
+ te vragen tot cookies voordat Shopify het voor je kan openen.
15
15
  top_level_interaction_action: Doorgaan
16
16
  request_storage_access_heading: "%{app} heeft toegang tot cookies nodig"
17
- request_storage_access_body: Hiermee kan de app u verifiëren door uw persoonlijke
17
+ request_storage_access_body: Hiermee kan de app je verifiëren door je persoonlijke
18
18
  gegevens tijdelijk op te slaan. Klik op Doorgaan en sta cookies toe om de app
19
19
  te gebruiken.
20
20
  request_storage_access_footer: Cookies verlopen na 30 dagen.
@@ -4,7 +4,7 @@ pt-BR:
4
4
  could_not_log_in: Não foi possível fazer login na Shopify store
5
5
  invalid_shop_url: Domínio de loja inválido
6
6
  enable_cookies_heading: Habilitar cookies de %{app}
7
- enable_cookies_body: Você deve habilitar manualmente os cookies neste navegador
7
+ enable_cookies_body: Você precisa habilitar manualmente os cookies neste navegador
8
8
  para usar %{app} dentro da Shopify.
9
9
  enable_cookies_footer: Os cookies permitem que o app o autentique armazenando temporariamente
10
10
  suas preferências e dados pessoais. Eles expiram depois de 30 dias.
@@ -3,12 +3,12 @@ th:
3
3
  logged_out: ออกจากระบบสำเร็จ
4
4
  could_not_log_in: ไม่สามารถเข้าสู่ระบบร้านค้า Shopify ได้
5
5
  invalid_shop_url: โดเมนร้านค้าไม่ถูกต้อง
6
- enable_cookies_heading: เปิดใช้งานคุกกี้จาก %{app}
7
- enable_cookies_body: คุณต้องเปิดใช้งานคุกกี้ด้วยตนเองในเบราว์เซอร์นี้เพื่อใช้งาน
8
- %{app} ภายใน Shopify
6
+ enable_cookies_heading: เปิดใช้คุกกี้จาก %{app}
7
+ enable_cookies_body: คุณต้องเปิดใช้คุกกี้ด้วยตนเองในเบราว์เซอร์นี้เพื่อใช้งาน %{app}
8
+ ภายใน Shopify
9
9
  enable_cookies_footer: คุกกี้ช่วยให้แอปตรวจสอบความถูกต้องของคุณด้วยการจัดเก็บความชื่นชอบและข้อมูลส่วนตัวของคุณชั่วคราว
10
10
  คุกกี้จะหมดอายุหลังจาก 30 วัน
11
- enable_cookies_action: เปิดใช้งานคุกกี้
11
+ enable_cookies_action: เปิดใช้คุกกี้
12
12
  top_level_interaction_heading: เบราว์เซอร์ของคุณต้องรับรองความถูกต้องของ %{app}
13
13
  top_level_interaction_body: เบราว์เซอร์ของคุณต้องการแอปอย่าง %{app} เพื่อขอให้คุณเข้าถึงคุกกี้ก่อนที่
14
14
  Shopify จะสามารถเปิดมันให้คุณได้
@@ -0,0 +1,22 @@
1
+ ---
2
+ vi:
3
+ logged_out: Đã đăng xuất thành công
4
+ could_not_log_in: Không thể đăng nhập vào cửa hàng trên Shopify
5
+ invalid_shop_url: Miền cửa hàng không hợp lệ
6
+ enable_cookies_heading: Bật cookie từ %{app}
7
+ enable_cookies_body: Bạn phải bật cookie trong trình duyệt này theo cách thủ công
8
+ để sử dụng %{app} trong Shopify.
9
+ enable_cookies_footer: Cookie cho phép ứng dụng xác thực bạn bằng cách tạm thời
10
+ lưu trữ tùy chọn và thông tin cá nhân của bạn. Những thông tin này sẽ hết hạn
11
+ sau 30 ngày.
12
+ enable_cookies_action: Bật cookie
13
+ top_level_interaction_heading: Trình duyệt của bạn cần xác thực %{app}
14
+ top_level_interaction_body: Trình duyệt của bạn cần các ứng dụng như %{app} để yêu
15
+ cầu quyền truy cập vào cookie thì Shopify mới có thể mở giúp bạn.
16
+ top_level_interaction_action: Tiếp tục
17
+ request_storage_access_heading: "%{app} cần quyền truy cập cookie"
18
+ request_storage_access_body: Nhờ vậy, ứng dụng có thể xác thực bạn bằng cách tạm
19
+ thời lưu trữ thông tin cá nhân của bạn. Nhấp vào tiếp tục và cho phép cookie sử
20
+ dụng ứng dụng.
21
+ request_storage_access_footer: Cookie sẽ hết hạn sau 30 ngày.
22
+ request_storage_access_action: Tiếp tục
@@ -8,7 +8,7 @@ zh-CN:
8
8
  enable_cookies_footer: Cookie 使此应用能够通过暂时存储您的偏好设置和个人信息来验证您的身份。这些信息将在 30 天后过期。
9
9
  enable_cookies_action: 启用 Cookie
10
10
  top_level_interaction_heading: 您的浏览器需要对 %{app} 进行验证
11
- top_level_interaction_body: 您的浏览器要求类似 %{app} 的应用向您请求访问 Cookie,之后 Shopify 才能为您打开它。
11
+ top_level_interaction_body: 您的浏览器要求类似 %{app} 的应用向您申请访问 Cookie,之后 Shopify 才能为您打开它。
12
12
  top_level_interaction_action: 继续
13
13
  request_storage_access_heading: "%{app} 需要访问 Cookie"
14
14
  request_storage_access_body: 这使此应用能够通过暂时存储您的个人信息来验证您的身份。单击继续并启用 Cookie 以使用此应用。
data/config/routes.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ShopifyApp::Engine.routes.draw do
2
3
  controller :sessions do
3
4
  get 'login' => :new, :as => :login
data/docs/Quickstart.md CHANGED
@@ -1,103 +1,31 @@
1
- Quickstart
2
- ==========
1
+ # Quickstart
3
2
 
4
- Get started building and deploying a new Shopify App to Heroku in just a few minutes. This guide assumes you have Ruby/Rails installed on your computer already; if you haven't done that already start with [this guide.](https://guides.rubyonrails.org/v5.0/getting_started.html#installing-rails)
3
+ This guide assumes you have completed the steps to create a new Rails app using the Shopify App gem found in the [*Usage*](/README.md#usage) section of the project's [*README*](/README.md).
5
4
 
6
- 1. New Rails App (with postgres)
7
- --------------------------------
5
+ #### Table of contents
8
6
 
9
- To create a new Rails app and use this generator, open your terminal and run the following commands:
7
+ [Make your app available to the internet](#make-your-app-available-to-the-internet)
10
8
 
11
- ```sh
12
- $ rails new test-app --database=postgresql
13
- $ cd test-app
14
- $ git init
15
- $ git add .
16
- $ git commit -m 'new rails app'
17
- ```
18
-
19
- 2. Create a new Heroku app
20
- --------------------------
21
-
22
- The next step is to create a new Heroku app to host your application. If you haven't got a Heroku account yet, create a free account [here](https://www.heroku.com/).
23
-
24
- Head to the Heroku dashboard and create a new app, or run the following commands with the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli#download-and-install) installed, substituting `name` for the name of your own app:
25
-
26
- CLI:
27
- ```sh
28
- $ heroku create name
29
- $ heroku git:remote -a name
30
- ```
31
-
32
- Once you have created an app on Heroku, we need to let Git know where the Heroku server is so we can deploy to it later. Copy the app's name from your Heroku dashboard and substitute `appname.git` with the name you chose earlier:
9
+ [Use Shopify App Bridge to embed your app in the Shopify Admin](#use-shopify-app-bridge-to-embed-your-app-in-the-shopify-admin)
33
10
 
34
- web:
35
- ```sh
36
- # https://dashboard.heroku.com/new
37
- $ git remote add heroku git@heroku.com:appname.git
38
- ```
11
+ ## Make your app available to the internet
39
12
 
40
- 3. Create a new App in the Shopify Partner dashboard
41
- -----------------------------------------
42
- * Create a Shopify app in the [Partners dashboard](https://partner.shopify.com). For this tutorial, you can choose either a public or custom app, but you can [learn about App Types here.](https://help.shopify.com/en/manual/apps/app-types)
43
- [https://app.shopify.com/services/partners/api_clients](https://app.shopify.com/services/partners/api_clients)
44
- * Set the callback url to `https://<appname>.herokuapp.com/`
45
- * Choose an embedded app
46
- * Set the app's `redirect_uri` to `https://<appname>.herokuapp.com/auth/shopify/callback`
13
+ 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](/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_controller.rb) or receive [webhooks](/docs/shopify_app/webhooks.md).
47
14
 
48
- 4. Add ShopifyApp to Gemfile
49
- ----------------------------
15
+ Use a tunneling service like [ngrok](https://ngrok.com/), [Beeceptor](https://beeceptor.com/), [Mockbin](http://mockbin.org/), or [Hookbin](https://hookbin.com/) to make your development environment accessible to the internet.
50
16
 
51
- Run these commands to add the `shopify_app` Gem to your app:
17
+ For example with [ngrok](https://ngrok.com/), run this command to set up a tunnel proxy to Rails' default port:
52
18
 
53
19
  ```sh
54
- $ echo "gem 'shopify_app'" >> Gemfile
55
- $ bundle install
20
+ ngrok http 3000
56
21
  ```
57
22
 
58
- **Note:** we recommend using the latest version of Shopify Gem. Check the [Git tags](https://github.com/Shopify/shopify_app/tags) to see the latest release version and then add it to your Gemfile e.g `gem 'shopify_app', '~> 7.0.0'`
59
-
60
- 5. Run the ShopifyApp generator
61
- -------------------------------
62
-
63
- Generate the code for your app by running these commands:
64
-
65
- ```sh
66
- # Use the keys from your app you created in the partners area
67
- $ rails generate shopify_app --api_key <shopify_api_key> --secret <shopify_api_secret>
68
- $ git add .
69
- $ git commit -m 'generated shopify app'
70
- ```
71
-
72
- If you forget to set your keys or redirect uri above, you will find them in the shopify_app initializer at: `/config/initializers/shopify_app.rb`.
73
-
74
- We recommend adding a gem or utilizing environment variables (`.env`) to handle your keys before releasing your app. [Learn more about using environment variables.](https://www.honeybadger.io/blog/ruby-guide-environment-variables/)
75
-
76
- 6. Deploy your app
77
- ---------
78
-
79
- Once you've generated your app, push it into your Heroku environment to see it up and running:
80
- ```sh
81
- $ git push heroku
82
- $ heroku run rake db:migrate
83
- ```
84
-
85
- 7. Install the App!
86
- -------------------
87
-
88
- Ensure you have created a [development store](https://help.shopify.com/en/api/getting-started/making-your-first-request#create-a-development-store) using the Shopify Partner Dashboard. If you don't already have one, [create one by following these instructions](https://help.shopify.com/en/api/getting-started/making-your-first-request#create-a-development-store).
89
-
90
- ##### Note: The following step will cause your store to become `transfer-disabled.` Read more about store transfer and why it's important [here](https://help.shopify.com/en/api/guides/store-transfers#transfer-disabled-stores). This is an irreversible change, so be sure you don't plan to transfer this store to a merchant.
91
-
92
- Install the app onto your new development store using the Partner Dashboard. Log in to your account, visit the apps page, click the app you created earlier, and looking for the `Test your app` instructions where you can select a store to install your app on.
93
-
94
- ![Installing an app on the partners dashboard dropdown](/docs/install-on-dev-shop.png)
23
+ See the [*Embed the app in Shopify*](https://shopify.dev/tutorials/build-rails-react-app-that-uses-app-bridge-authentication#embed-the-app-in-shopify) section of [*Build a Shopify app with Rails, React, and App Bridge*](https://shopify.dev/tutorials/build-rails-react-app-that-uses-app-bridge-authentication) to learn more.
95
24
 
96
- ### OR
25
+ ## Use Shopify App Bridge to embed your app in the Shopify Admin
97
26
 
98
- ![Installing an app on the partners dashboard card](/docs/test-your-app.png)
27
+ A basic example of using [*Shopify App Bridge*](https://shopify.dev/tools/app-bridge) is included in the install generator. An instance Shopify App Bridge is automatically initialized in [shopify_app.js](https://github.com/Shopify/shopify_app/blob/master/lib/generators/shopify_app/install/templates/shopify_app.js).
99
28
 
100
- 8. Great work!
101
- -------------------
29
+ The [flash_messages.js](https://github.com/Shopify/shopify_app/blob/master/lib/generators/shopify_app/install/templates/flash_messages.js) file 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).
102
30
 
103
- You're done creating your first app on Shopify. Keep going and learn more by [diving into our full documentation](https://help.shopify.com/en/api/getting-started), or join our [community of developers.](https://community.shopify.com/c/Shopify-Apps/bd-p/shopify-apps)
31
+ 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).
data/docs/Releasing.md CHANGED
@@ -1,17 +1,21 @@
1
- Releasing ShopifyApp
1
+ # Releasing ShopifyApp
2
2
 
3
- 1. Check the Semantic Versioning page for info on how to version the new release: http://semver.org
4
- 2. Create a pull request with the following changes:
5
- * Update the version of ShopifyApp in lib/shopify_app/version.rb
6
- * Add a CHANGELOG entry for the new release with the date
7
- * Change the title of the PR to something like: "Packaging for release X.Y.Z"
8
- 3. Merge your pull request
9
- 4. Pull from master so you have the latest version of the shopify_app
10
- 5. Tag the HEAD with the version (Leave REV blank for HEAD or provide a SHA)
11
- $ git tag vX.Y.Z
12
- 6. Push out your tags
13
- $ git push --tags
14
- 7. Use Shipit to build and push the gem
3
+ 1. Make the code changes in a separate PR that doesn't modify the version.
4
+ 1. After that is merged, check the Semantic Versioning page for info on how to version the new release: http://semver.org
5
+ 1. Create a pull request with the following changes:
6
+ - Update the version of ShopifyApp in lib/shopify_app/version.rb
7
+ - Update the version of shopify_app in package.json
8
+ - Run `bundle` to update `Gemfile.lock`
9
+ - Add a CHANGELOG entry for the new release with the date
10
+ - Change the title of the PR to something like: "Packaging for release X.Y.Z"
11
+ 1. Merge your pull request
12
+ 1. Checkout and pull from master so you have the latest version of the shopify_app
13
+ 1. Tag the HEAD with the version
14
+ ```bash
15
+ $ git tag -f vX.Y.Z && git push --tags --force
16
+ ```
17
+ 1. Check that Create Release workflow successfully runs
18
+ 1. Use Shipit to build and push the gem
15
19
 
16
- If you see an error like 'You need to create the vX.Y.X tag first', clear GIT
20
+ If you see an error like 'You need to create the vX.Y.X tag first', clear git
17
21
  cache in Shipit settings
@@ -1,7 +1,24 @@
1
- Troubleshooting Shopify App
2
- ===========
1
+ # Troubleshooting Shopify App
3
2
 
4
- ### Generator shopify_app:install hangs
3
+ #### Table of contents
4
+
5
+ [Generators](#generators)
6
+ * [The `shopify_app:install` generator hangs](#the-shopifyappinstall-generator-hangs)
7
+
8
+ [Rails](#rails)
9
+ * [Known issues with Rails `v6.1`](#known-issues-with-rails-v61)
10
+
11
+ [App installation](#app-installation)
12
+ * [My app won't install](#my-app-wont-install)
13
+ * [My app keeps redirecting to login](#my-app-keeps-redirecting-to-login)
14
+
15
+ [JWT session tokens](#jwt-session-tokens)
16
+ * [My app is still using cookies to authenticate](#my-app-is-still-using-cookies-to-authenticate)
17
+ * [My app can't make requests to the Shopify API](#my-app-cant-make-requests-to-the-shopify-api)
18
+
19
+ ## Generators
20
+
21
+ ### The shopify_app:install generator hangs
5
22
 
6
23
  Rails uses spring by default to speed up development. To run the generator, spring has to be stopped:
7
24
 
@@ -11,6 +28,114 @@ $ bundle exec spring stop
11
28
 
12
29
  Run shopify_app generator again.
13
30
 
14
- ### App installation fails with 'The page you’re looking for could not be found' if the app was installed before
31
+ ## Rails
32
+
33
+ ### Known issues with Rails `v6.1`
34
+
35
+ If you recently upgraded your application's `Rails::Application` configuration to load the default configuration for Rails `v6.1`, then you will need to update the following `cookies_same_site_protection` ActionDispatch configuration.
36
+
37
+ ```diff
38
+ # config/application.rb
39
+
40
+ require_relative 'boot'
41
+
42
+ require 'rails/all'
43
+
44
+ Bundler.require(*Rails.groups)
45
+
46
+ module AppName
47
+ class Application < Rails::Application
48
+ + config.load_defaults 6.1
49
+
50
+ + config.action_dispatch.cookies_same_site_protection = :none
51
+ ...
52
+ end
53
+ end
54
+ ```
55
+
56
+ As of Rails `v6.1`, the same-site cookie protection setting defaults to `Lax`. This does not allow an embedded app to make cross-domain requests in the Shopify Admin.
57
+
58
+ Alternatively, you can upgrade to [`v17.2.0` of the shopify_app gem](/docs/Upgrading.md#upgrading-to-v1720).
59
+
60
+ ## App installation
61
+
62
+ ### My app won't install
63
+
64
+ #### App installation fails with 'The page you’re looking for could not be found' if the app was installed before
15
65
 
16
66
  This issue can occur when the session (the model you set as `ShopifyApp::SessionRepository.storage`) isn't deleted when the user uninstalls your app. A possible fix for this is listening to the `app/uninstalled` webhook and deleting the corresponding session in the webhook handler.
67
+
68
+ ## JWT session tokens
69
+
70
+ ### My app is still using cookies to authenticate
71
+
72
+ #### `shopify_app` gem version
73
+
74
+ Ensure the app is using shopify_app gem v13.x.x+. See [*Upgrading to `v13.0.0`*](/docs/Upgrading.md#upgrading-to-v1300).
75
+
76
+ #### `shopify_app` gem Rails configuration
77
+
78
+ Edit `config/initializer/shopify_app.rb` and ensure the following configurations are set:
79
+
80
+ ```diff
81
+ + config.embedded_app = true
82
+
83
+ + config.allow_jwt_authentication = true
84
+ + config.allow_cookie_authentication = false
85
+
86
+ # This line should already exist if you're using shopify_app gem 13.x.x+
87
+ + config.shop_session_repository = 'Shop'
88
+ ```
89
+
90
+ #### Inspect server logs
91
+
92
+ If you have checked the configurations above, and the app is still using cookies, then it is possible that the `shopify_app` gem defaulted to relying on cookies. This would happen when your browser allows third-party cookies and a session token was not successfully found as part of your request.
93
+
94
+ In this case, check the server logs to see if the session token was invalid:
95
+
96
+ ```los
97
+ [ShopifyApp::JWT] Failed to validate JWT: [JWT::<Error>] <Failure message>
98
+ ```
99
+
100
+ *Example*
101
+
102
+ ```
103
+ [ShopifyApp::JWT] Failed to validate JWT: [JWT::ImmatureSignature] Signature nbf has not been reached
104
+ ```
105
+
106
+ **Note:** In a local development environment, you may want to temporarily update your `Gemfile` to point to a local instance of the `shopify_app` library instad of an installed gem. This will enable you to use a debugging tool like `byebug` to debug the library.
107
+
108
+ ```diff
109
+ - gem 'shopify_app', '~> 14.2'
110
+ + gem 'shopify_app', path: '/path/to/shopify_app'
111
+ ```
112
+
113
+ ### My app can't make requests to the Shopify API
114
+
115
+ > **Note:** Session tokens cannot be used to make authenticated requests to the Shopify API. Learn more about authenticating your backend requests to Shopify APIs at [Shopify API authentication](https://shopify.dev/concepts/about-apis/authentication).
116
+
117
+ #### The Shopify API returns `401 Unauthorized`
118
+
119
+ If your app uses [user-based token storage](/docs/shopify_app/session-repository.md#user-based-token-storage), then your app is configured to use **online** access tokens (see [API access modes](https://shopify.dev/concepts/about-apis/authentication#api-access-modes) to learn the difference between "online" and "offline" access tokens ). Unlike offline access tokens, online access tokens expire daily and cannot be used to make authenticated requests to the Shopify API once they expire.
120
+
121
+ Converting your app to use session tokens means that your app will most likely not go through the OAuth flow as often as it did when relying on cookie sessions. Since the online access tokens stored in your app's database are refreshed during OAuth, this may cause your app's user session repository to use expired online access tokens.
122
+
123
+ If the Shopify API returns `401 Unauthorized`, handle this error on your app by redirecting the user to your login path to start the OAuth flow. As a result, your app will be given a new online access token for the current user.
124
+
125
+ > **Note:** The following are examples to common app configurations. Your specific use-case may differ.
126
+
127
+ ##### Example solution
128
+
129
+ Add the following line to your app's unauthorized response handler:
130
+
131
+ ```diff
132
+ + redirect_to(ShopifyApp.configuration.login_url, shop: current_shopify_domain)
133
+ ```
134
+
135
+ _Example:_ If your embedded app cannot handle server-side XHR redirects, then configure your app's unauthorized response handler to set a response header:
136
+
137
+ ```
138
+ X-Shopify-API-Request-Failure-Unauthorized: true
139
+ ```
140
+
141
+ Then, use the [Shopify App Bridge Redirect](https://shopify.dev/tools/app-bridge/actions/navigation/redirect) action to redirect your app frontend to the app login URL if this header is set.
data/docs/Upgrading.md ADDED
@@ -0,0 +1,126 @@
1
+ # Upgrading
2
+
3
+ This file documents important changes needed to upgrade your app's Shopify App version to a new major version.
4
+
5
+ #### Table of contents
6
+
7
+ [Upgrading to `v17.2.0`](#upgrading-to-v1720)
8
+
9
+ [Upgrading to `v13.0.0`](#upgrading-to-v1300)
10
+
11
+ [Upgrading to `v11.7.0`](#upgrading-to-v1170)
12
+
13
+ [Upgrading from `v8.6` to `v9.0.0`](#upgrading-from-v86-to-v900)
14
+
15
+ ## Upgrading to `v17.2.0`
16
+
17
+ ### Different SameSite cookie attribute behaviour
18
+
19
+ To support Rails `v6.1`, the [`SameSiteCookieMiddleware`](/lib/shopify_app/middleware/same_site_cookie_middleware.rb) was updated to configure cookies to `SameSite=None` if the app is embedded. Before this release, cookies were configured to `SameSite=None` only if this attribute had not previously been set before.
20
+
21
+ ```diff
22
+ # same_site_cookie_middleware.rb
23
+ - cookie << '; SameSite=None' unless cookie =~ /;\s*samesite=/i
24
+ + cookie << '; SameSite=None' if ShopifyApp.configuration.embedded_app?
25
+ ```
26
+
27
+ By default, Rails `v6.1` configures `SameSite=Lax` on all cookies that don't specify this attribute.
28
+
29
+ ## Upgrading to `v13.0.0`
30
+
31
+ Version 13.0.0 adds the ability to use both user and shop sessions, concurrently. This however involved a large
32
+ change to how session stores work. Here are the steps to migrate to 13.x
33
+
34
+ ### Changes to `config/initializers/shopify_app.rb`
35
+
36
+ - *REMOVE* `config.per_user_tokens = [true|false]` this is no longer needed
37
+ - *CHANGE* `config.session_repository = 'Shop'` To `config.shop_session_repository = 'Shop'`
38
+ - *ADD (optional)* User Session Storage `config.user_session_repository = 'User'`
39
+
40
+ ### Shop Model Changes (normally `app/models/shop.rb`)
41
+
42
+ - *CHANGE* `include ShopifyApp::SessionStorage` to `include ShopifyApp::ShopSessionStorage`
43
+
44
+ ### Changes to the @shop_session instance variable (normally in `app/controllers/*.rb`)
45
+
46
+ - *CHANGE* if you are using shop sessions, `@shop_session` will need to be changed to `@current_shopify_session`.
47
+
48
+ ### Changes to Rails `session`
49
+
50
+ - *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.
51
+
52
+ ### Changes to `ShopifyApp::LoginProtection`
53
+
54
+ `ShopifyApp::LoginProtection`
55
+
56
+ - CHANGE if you are using `ShopifyApp::LoginProtection#shopify_session` in your code, it will need to be
57
+ changed to `ShopifyApp::LoginProtection#activate_shopify_session`
58
+ - CHANGE if you are using `ShopifyApp::LoginProtection#clear_shop_session` in your code, it will need to be
59
+ changed to `ShopifyApp::LoginProtection#clear_shopify_session`
60
+
61
+ ### Notes
62
+ You do not need a user model; a shop session is fine for most applications.
63
+
64
+ ---
65
+
66
+ ## Upgrading to `v11.7.0`
67
+
68
+ ### Session storage method signature breaking change
69
+ 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.
70
+
71
+ ---
72
+
73
+ ## Upgrading from `v8.6` to `v9.0.0`
74
+
75
+ ### Configuration change
76
+
77
+ Add an API version configuration in `config/initializers/shopify_app.rb`
78
+ 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.
79
+ ```ruby
80
+ config.api_version = '2019-04'
81
+ ```
82
+
83
+ ### Session storage change
84
+
85
+ You will need to add an `api_version` method to your session storage object. The default implementation for this is.
86
+ ```ruby
87
+ def api_version
88
+ ShopifyApp.configuration.api_version
89
+ end
90
+ ```
91
+
92
+ ### Generated file change
93
+
94
+ `embedded_app.html.erb` the usage of `shop_session.url` needs to be changed to `shop_session.domain`
95
+ ```erb
96
+ <script type="text/javascript">
97
+ ShopifyApp.init({
98
+ apiKey: "<%= ShopifyApp.configuration.api_key %>",
99
+
100
+ shopOrigin: "<%= "https://#{ @shop_session.url }" if @shop_session %>",
101
+
102
+ debug: false,
103
+ forceRedirect: true
104
+ });
105
+ </script>
106
+ ```
107
+ is changed to
108
+ ```erb
109
+ <script type="text/javascript">
110
+ ShopifyApp.init({
111
+ apiKey: "<%= ShopifyApp.configuration.api_key %>",
112
+
113
+ shopOrigin: "<%= "https://#{ @shop_session.domain }" if @shop_session %>",
114
+
115
+ debug: false,
116
+ forceRedirect: true
117
+ });
118
+ </script>
119
+ ```
120
+
121
+ ### ShopifyAPI changes
122
+
123
+ 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.
124
+
125
+ [dashboard]:https://partners.shopify.com
126
+ [app-bridge]:https://help.shopify.com/en/api/embedded-apps/app-bridge