shopify_app 7.4.0 → 8.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +5 -5
  2. data/.babelrc +5 -0
  3. data/.github/CODEOWNERS +1 -0
  4. data/.github/probots.yml +2 -0
  5. data/.gitignore +5 -0
  6. data/.nvmrc +1 -0
  7. data/.rubocop.yml +10 -0
  8. data/.ruby-version +1 -0
  9. data/.travis.yml +26 -3
  10. data/CHANGELOG.md +95 -0
  11. data/Gemfile +2 -0
  12. data/README.md +113 -56
  13. data/app/assets/images/storage_access.svg +2 -0
  14. data/app/assets/javascripts/shopify_app/enable_cookies.js +3 -0
  15. data/app/assets/javascripts/shopify_app/itp_helper.js +40 -0
  16. data/app/assets/javascripts/shopify_app/partition_cookies.js +7 -0
  17. data/app/assets/javascripts/shopify_app/redirect.js +33 -0
  18. data/app/assets/javascripts/shopify_app/request_storage_access.js +3 -0
  19. data/app/assets/javascripts/shopify_app/storage_access.js +121 -0
  20. data/app/assets/javascripts/shopify_app/storage_access_redirect.js +17 -0
  21. data/app/assets/javascripts/shopify_app/top_level.js +2 -0
  22. data/app/assets/javascripts/shopify_app/top_level_interaction.js +11 -0
  23. data/app/controllers/shopify_app/authenticated_controller.rb +3 -4
  24. data/{lib/shopify_app/sessions_concern.rb → app/controllers/shopify_app/callback_controller.rb} +27 -38
  25. data/app/controllers/shopify_app/sessions_controller.rb +120 -2
  26. data/app/controllers/shopify_app/webhooks_controller.rb +11 -3
  27. data/app/views/shopify_app/partials/_button_styles.html.erb +104 -0
  28. data/app/views/shopify_app/partials/_card_styles.html.erb +33 -0
  29. data/app/views/shopify_app/partials/_empty_state_styles.html.erb +129 -0
  30. data/app/views/shopify_app/partials/_layout_styles.html.erb +167 -0
  31. data/app/views/shopify_app/partials/_typography_styles.html.erb +35 -0
  32. data/app/views/shopify_app/sessions/enable_cookies.html.erb +59 -0
  33. data/app/views/shopify_app/sessions/new.html.erb +88 -60
  34. data/app/views/shopify_app/sessions/request_storage_access.html.erb +67 -0
  35. data/app/views/shopify_app/sessions/top_level_interaction.html.erb +63 -0
  36. data/app/views/shopify_app/shared/redirect.html.erb +22 -0
  37. data/config/locales/de.yml +21 -2
  38. data/config/locales/en.yml +12 -0
  39. data/config/locales/es.yml +21 -2
  40. data/config/locales/fr.yml +22 -2
  41. data/config/locales/it.yml +22 -0
  42. data/config/locales/ja.yml +16 -2
  43. data/config/locales/nl.yml +21 -0
  44. data/config/locales/pt-BR.yml +22 -0
  45. data/config/locales/zh-CN.yml +16 -0
  46. data/config/locales/zh-TW.yml +17 -0
  47. data/config/routes.rb +11 -1
  48. data/docs/Quickstart.md +26 -23
  49. data/docs/Releasing.md +1 -0
  50. data/karma.conf.js +43 -0
  51. data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +3 -1
  52. data/lib/generators/shopify_app/home_controller/templates/home_controller.rb +1 -0
  53. data/lib/generators/shopify_app/home_controller/templates/index.html.erb +14 -0
  54. data/lib/generators/shopify_app/home_controller/templates/shopify_app_ready_script.html.erb +1 -5
  55. data/lib/generators/shopify_app/install/install_generator.rb +3 -13
  56. data/lib/generators/shopify_app/install/templates/_flash_messages.html.erb +13 -9
  57. data/lib/generators/shopify_app/install/templates/shopify_app.rb +4 -1
  58. data/lib/generators/shopify_app/install/templates/shopify_provider.rb +19 -4
  59. data/lib/generators/shopify_app/rotate_shopify_token_job/rotate_shopify_token_job_generator.rb +16 -0
  60. data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token.rake +17 -0
  61. data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token_job.rb +42 -0
  62. data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +3 -3
  63. data/lib/generators/shopify_app/shop_model/templates/shop.rb +0 -1
  64. data/lib/shopify_app.rb +21 -17
  65. data/lib/shopify_app/configuration.rb +26 -8
  66. data/lib/shopify_app/{app_proxy_verification.rb → controller_concerns/app_proxy_verification.rb} +1 -1
  67. data/lib/shopify_app/controller_concerns/embedded_app.rb +19 -0
  68. data/lib/shopify_app/controller_concerns/itp.rb +45 -0
  69. data/lib/shopify_app/{localization.rb → controller_concerns/localization.rb} +6 -0
  70. data/lib/shopify_app/controller_concerns/login_protection.rb +135 -0
  71. data/lib/shopify_app/{webhook_verification.rb → controller_concerns/webhook_verification.rb} +10 -6
  72. data/lib/shopify_app/engine.rb +10 -0
  73. data/lib/shopify_app/{scripttags_manager_job.rb → jobs/scripttags_manager_job.rb} +0 -0
  74. data/lib/shopify_app/{webhooks_manager_job.rb → jobs/webhooks_manager_job.rb} +0 -0
  75. data/lib/shopify_app/{scripttags_manager.rb → managers/scripttags_manager.rb} +0 -0
  76. data/lib/shopify_app/{webhooks_manager.rb → managers/webhooks_manager.rb} +0 -0
  77. data/lib/shopify_app/session/in_memory_session_store.rb +27 -0
  78. data/lib/shopify_app/{shopify_session_repository.rb → session/session_repository.rb} +0 -0
  79. data/lib/shopify_app/{session_storage.rb → session/session_storage.rb} +9 -0
  80. data/lib/shopify_app/utils.rb +2 -2
  81. data/lib/shopify_app/version.rb +1 -1
  82. data/package-lock.json +23 -0
  83. data/package.json +28 -0
  84. data/service.yml +7 -0
  85. data/shipit.rubygems.yml +2 -0
  86. data/shopify_app.gemspec +5 -4
  87. data/translation.yml +7 -0
  88. data/webpack.config.js +24 -0
  89. data/yarn.lock +4594 -0
  90. metadata +80 -27
  91. data/lib/generators/shopify_app/install/templates/shopify_session_repository.rb +0 -23
  92. data/lib/generators/shopify_app/shop_model/templates/shopify_session_repository.rb +0 -9
  93. data/lib/shopify_app/in_memory_session_store.rb +0 -25
  94. data/lib/shopify_app/login_protection.rb +0 -119
  95. data/lib/shopify_app/shop.rb +0 -15
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg enable-background="new 0 0 1920 1080" version="1.1" viewBox="0 0 1920 1080" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><polygon points="1345 330.75 1345 437.24 1224.7 437.24 1224.7 676.56 873.52 676.56 874.04 643.85 1203.2 330.23" fill="#fff"/><path d="m1095.7 677.54c-18.553 0.074-37.107 0.163-55.66 0.126-18.553 0.056-37.107-0.188-55.66-0.233l-13.915-0.063-13.915 0.044-27.83 0.094c-18.553 0.128-37.107-5e-3 -55.66-0.056l-1.266-3e-3 3e-3 -1.259 0.047-22.532-0.093-22.532-0.068-11.266 6e-3 -11.266 0.019-22.532h2.703l0.111 22.532c0.053 7.511 0.06 15.022 0.038 22.532l-0.094 45.065-1.407-1.407c18.553 7e-3 37.107-0.041 55.66 0.086l27.83 0.131 13.915 0.066 13.915-0.028c18.553-8e-3 37.107-0.151 55.66-0.019 18.553 0.099 37.107 0.049 55.66-0.181v2.701z" fill="#0C1238"/><path d="m1225 677.54c-9.24 0.123-18.48 0.187-27.72 0.077l-13.86-0.213c-2.31-0.051-4.62-0.023-6.93 1e-3l-6.93 0.062c-9.24 0.156-18.48 0.076-27.72-0.054-2.31-0.034-4.62 1e-3 -6.93 2e-3l-6.93 0.121c-4.62 0.062-9.24-2e-3 -13.86 3e-3v-2.703c4.62-0.048 9.24-0.165 13.86-0.157l6.93 0.025c2.31 0.027 4.62 0.088 6.93 0.076 9.24-0.024 18.48-0.031 27.72 0.145 4.62 0.038 9.24 0.163 13.86 0.126l13.86-0.081c4.62-0.04 9.24 0.088 13.86 0.101 2.31 0.047 4.62-0.048 6.93-0.065 2.31-0.026 4.62-0.07 6.93-0.169v2.703z" fill="#0C1238"/><path d="m871.68 561.78l-0.13-115.72 0.07-115.72 1e-3 -1.414 1.411 3e-3 117.9 0.228 117.9-0.138 58.951-0.061 58.951 0.072 117.9 0.09 1.218 1e-3 4e-3 1.221 0.156 53.426-0.026 53.426h-2.703l-0.154-53.426 0.04-53.426 1.466 1.466-235.8-0.148-117.9-0.193-117.9 0.087 1.212-1.212-0.084 115.72c-0.058 19.286 0.032 38.573 0.074 57.859l0.15 57.859h-2.705z" fill="#0C1238"/><g fill="#E6E8F0"><circle cx="891.37" cy="344.49" r="6.812"/><circle cx="912.86" cy="345.01" r="6.812"/><circle cx="934.34" cy="345.54" r="6.812"/><path d="m1202.7 352.87h-186.64c-0.552 0-1-0.448-1-1v-11.624c0-0.552 0.448-1 1-1h186.64c0.552 0 1 0.448 1 1v11.624c0 0.552-0.448 1-1 1z" stroke="#F0F3F5" stroke-miterlimit="10"/><rect x="1288.6" y="339.25" width="17.816" height="13.624"/><path d="m1327.4 352.87h-15.816c-0.552 0-1-0.448-1-1v-11.624c0-0.552 0.448-1 1-1h15.816c0.552 0 1 0.448 1 1v11.624c0 0.552-0.447 1-1 1z"/></g><g fill="none" stroke="#8891EA" stroke-miterlimit="10" stroke-width="8"><path d="m1098.3 576.8c-24.295 0-43.99-19.695-43.99-43.99v-29.485c0-2.209 1.791-4 4-4h79.98c2.209 0 4 1.791 4 4v29.485c0 24.295-19.695 43.99-43.99 43.99z"/><path d="m1066 499.33v-12.41c0-17.804 14.433-32.237 32.237-32.237s32.237 14.433 32.237 32.237v12.41"/></g><circle cx="1098.3" cy="529.08" r="8.966" fill="#8891EA"/><line x1="1098.3" x2="1098.3" y1="529.08" y2="546.68" fill="#fff" stroke="#8891EA" stroke-linecap="round" stroke-miterlimit="10" stroke-width="8"/><polygon points="1416.1 676.19 1358 748.57 1416.1 749.77 1225 749.77 1225 659.42 1416.1 437.19" fill="#fff"/><path d="m1415.2 497.07l-0.12-59.83 1.472 1.472-95.89-0.052-47.945-0.135c-15.982-0.023-31.963-0.14-47.945-0.085l1.2-1.2 0.139 78.077c0.086 26.026 4e-3 52.052-0.039 78.077l-0.076 78.077c0.056 26.026 0.201 52.052 0.145 78.077l-1.368-1.368 38.25 0.017v2.703l-38.251 0.1-1.444 4e-3 -6e-3 -1.454c-0.102-26.026-0.045-52.052-0.026-78.077l0.068-78.077 0.067-78.077 0.191-78.077 3e-3 -1.15h1.147l47.945-0.013 47.945-0.051 95.89 0.089 1.121 1e-3 4e-3 1.125 0.226 59.83h-2.703z" fill="#0C1238"/><path d="m1417.9 518.33c0.051 19.268 0.165 38.536 0.128 57.804l-0.022 28.902-0.134 28.902-0.134 28.902 0.061 28.902 0.087 28.902 0.046 14.451-0.034 14.451-3e-3 1.353-1.347-3e-3c-22.64-0.042-45.28-0.192-67.919-0.118l-33.96 0.144-33.96-0.025v-2.703l33.96-0.143 33.96 0.01c11.32 0.049 22.64 0.1 33.96 0.078l33.96-2e-3 -1.409 1.409c-0.03-19.268 0.125-38.536 0.178-57.804l0.103-28.902-0.051-28.902-0.051-28.902 0.081-28.902c0.128-19.268-0.116-38.536-0.204-57.804h2.704z" fill="#0C1238"/><path d="m1400.3 458.72h-160.44c-0.552 0-1-0.448-1-1v-11.624c0-0.552 0.448-1 1-1h160.44c0.552 0 1 0.448 1 1v11.624c0 0.552-0.448 1-1 1z" fill="#E6E8F0" stroke="#F0F3F5" stroke-miterlimit="10"/><path d="m1238.5 467.44c13.587-0.084 27.173-0.121 40.76-0.055l20.38 0.141c6.793 0.061 13.587-0.03 20.38-0.038 13.587-0.116 27.173-0.022 40.76 0.038 6.793 0.029 13.587-0.022 20.38-0.082 6.793-0.046 13.587 0 20.38-5e-3v1.802c-13.587 0.111-27.173 0.144-40.76 0.036-13.587 2e-3 -27.173 0.027-40.76-0.09-6.793-0.025-13.587-0.117-20.38-0.088l-20.38 0.054c-6.793 0.022-13.587-0.048-20.38-0.067-6.793-7e-3 -13.587 0.107-20.38 0.154v-1.8z" fill="#E6E8F0"/><path d="m891.69 362.56c36.392-0.084 72.784-0.121 109.18-0.055l54.588 0.141c18.196 0.062 36.392-0.034 54.588-0.043l218.35-0.043v1.802c-36.392 0.111-72.784 0.144-109.18 0.036l-109.18-0.09-54.588-0.088-54.588 0.054-54.588-0.067-54.588 0.154v-1.801z" fill="#E6E8F0"/><g fill="none" stroke="#8891EA" stroke-miterlimit="10" stroke-width="6"><path d="m1320.6 638.41c-17.878 0-32.371-14.493-32.371-32.371v-21.697c0-1.626 1.318-2.943 2.943-2.943h58.854c1.626 0 2.943 1.318 2.943 2.943v21.697c1e-3 17.878-14.491 32.371-32.369 32.371z"/><path d="m1296.9 581.4v-9.132c0-13.101 10.62-23.722 23.722-23.722 13.101 0 23.722 10.621 23.722 23.722v9.132"/></g><circle cx="1320.6" cy="604.5" r="5.88" fill="#8891EA"/><line x1="1320.6" x2="1320.6" y1="603.3" y2="616.25" fill="#fff" stroke="#8891EA" stroke-linecap="round" stroke-miterlimit="10" stroke-width="6"/><path d="m966.35 697.36l-0.029 13.745c-0.01 1.145 0.011 2.291-0.023 3.436l-0.124 3.436c-0.103 2.291 0.022 4.582 0.121 6.872l-1.912-1.912c10.168-0.857 20.337-0.478 30.505-0.36 5.084 0.104 10.168 0.133 15.252 0.178 5.084 6e-3 10.168 0.199 15.252 0.287l7.626 0.168 7.626 0.264c2.542 0.09 5.084 0.032 7.626 0.023 2.542-0.035 5.084 0.047 7.626 0.065 10.168 0.377 20.337-0.052 30.505 0.201l7.626 0.04c2.542 6e-3 5.084-0.283 7.626-0.394 5.084-0.14 10.168-0.184 15.252-0.268 5.084-0.072 10.168-0.071 15.252-0.204 2.542-0.07 5.084-0.088 7.626-0.118 2.542-0.019 5.084 0.1 7.626 0.143 10.168 0.462 20.337-0.303 30.505 0.192 2.542 0.145 5.084 0.163 7.626 0.139 2.542 0 5.084-0.038 7.626-0.099l15.252-0.314v3.936l-15.252 0.106c-5.084 0.024-10.168 0.012-15.252 0.3-10.168 0.483-20.337-0.281-30.505-0.213-20.337-1.165-40.673 0.704-61.01-0.137-2.542 0.117-5.084 0.33-7.626 0.382-2.542 0.092-5.084 0.173-7.626-0.018s-5.084-0.219-7.626-0.183c-2.542-2e-3 -5.084 0.099-7.626 0.081-2.542-0.027-5.084 0.026-7.626-0.066-1.271-0.039-2.542-0.079-3.813-0.09-1.271-0.022-2.542-0.05-3.813 0.018-2.542 0.097-5.084 0.355-7.626 0.327-1.271-0.037-2.542-0.06-3.813-0.12l-3.813-0.238c-2.542-0.162-5.084-0.324-7.626-0.268-2.542 0.109-5.084-0.092-7.626-0.222-2.542-0.112-5.084-0.326-7.626-0.371-2.542-0.094-5.084-0.061-7.626-0.038-5.084 0.101-10.168 0.266-15.252 0.414-2.542 0.071-5.084 0.122-7.626 0.123l-7.626-0.19-1.598-0.04 0.032-1.527c0.047-2.291 0.153-4.582 9e-3 -6.872l-0.162-3.436c-0.047-1.145-0.04-2.291-0.062-3.436l-0.186-13.745h3.934z" fill="#E6E8F0"/><path d="m1434.8 722.88l16.096 0.019 8.048 0.01c2.683 0.018 5.365-0.029 8.048 0.05l-1.89 1.89c0.07-3.44 0.218-6.88 0.086-10.32l-0.312-10.32c-0.261-6.88-0.364-13.76-0.339-20.639l0.314-41.279c0.052-6.88 0.033-13.76 0.144-20.639l0.275-20.639c0.057-6.88 0.274-13.76 0.375-20.639 0.058-6.88-0.069-13.76 0.033-20.639l0.226-20.639-0.071-10.32-0.046-5.16 0.032-5.16 0.11-20.639c0.012-3.44 0.045-6.88-0.068-10.32-0.149-3.44-0.261-6.88-0.361-10.32l-0.328-41.279c-0.074-6.88-0.188-13.76-0.211-20.639 0.028-6.88 0.177-13.76 0.261-20.639l1.77 1.77c-4.37-0.095-8.74 1e-3 -13.111 1e-3l-13.111 0.063c-4.37 1e-3 -8.74 0.084-13.111 0.016l-13.111-0.231c-4.37-0.118-8.74-0.058-13.111-0.055-4.37-4e-3 -8.74 0.077-13.111 0.113l-26.221 0.29v-3.936l26.221-0.107 13.111-0.052c4.37-0.026 8.74 2e-3 13.111-0.14l13.111-0.262c4.37-0.066 8.74 0.04 13.111 0.051l26.221 0.283 2.211 0.024-0.016 2.172c-0.049 6.88-0.045 13.76-0.139 20.639-0.152 6.88-0.325 13.76-0.304 20.639l0.499 41.279c-0.024 1.72-0.037 3.44-0.138 5.16l-0.297 5.16c-0.137 3.44-0.045 6.88 0.01 10.32 0.12 6.88 0.479 13.76 0.59 20.639 0.273 6.88-0.127 13.76-0.227 20.639-0.014 6.88 0.146 13.76 0.091 20.639 0.051 6.88-0.202 13.76-0.162 20.639 0.04 3.44 0.226 6.88 0.324 10.32 0.061 3.44 4e-3 6.88-0.082 10.32l-0.356 10.32c-0.047 1.72-0.141 3.44-0.149 5.16l2e-3 5.16c-0.012 1.72 0.032 3.44-0.026 5.16l-0.164 5.16-0.335 10.32c-0.306 13.76 0.065 27.519 0.289 41.279 0.074 3.44 0.091 6.88 0.13 10.32 0.059 3.44-0.071 6.88-0.098 10.32l-0.153 10.32c-0.053 1.72 0.021 3.44 0.049 5.16l0.139 5.16 0.044 1.627-1.73 0.06c-2.683 0.093-5.365 0.065-8.048 0.1l-8.048 0.061-16.096 0.121v-3.941z" fill="#E6E8F0"/></svg>
@@ -0,0 +1,3 @@
1
+ //= require ./itp_helper.js
2
+ //= require ./storage_access.js
3
+ //= require ./partition_cookies.js
@@ -0,0 +1,40 @@
1
+ (function() {
2
+ function ITPHelper(opts) {
3
+ this.itpContent = document.getElementById('TopLevelInteractionContent');
4
+ this.itpAction = document.getElementById('TopLevelInteractionButton');
5
+ this.redirectUrl = opts.redirectUrl;
6
+ }
7
+
8
+ ITPHelper.prototype.redirect = function() {
9
+ sessionStorage.setItem('shopify.top_level_interaction', true);
10
+ window.location.href = this.redirectUrl;
11
+ }
12
+
13
+ ITPHelper.prototype.userAgentIsAffected = function() {
14
+ return Boolean(document.hasStorageAccess);
15
+ }
16
+
17
+ ITPHelper.prototype.canPartitionCookies = function() {
18
+ var versionRegEx = /Version\/12\.0\.?\d? Safari/;
19
+ return versionRegEx.test(navigator.userAgent);
20
+ }
21
+
22
+ ITPHelper.prototype.setUpContent = function(onClick) {
23
+ this.itpContent.style.display = 'block';
24
+ this.itpAction.addEventListener('click', this.redirect.bind(this));
25
+ }
26
+
27
+ ITPHelper.prototype.execute = function() {
28
+ if (!this.itpContent) {
29
+ return;
30
+ }
31
+
32
+ if (this.userAgentIsAffected()) {
33
+ this.setUpContent();
34
+ } else {
35
+ this.redirect();
36
+ }
37
+ }
38
+
39
+ this.ITPHelper = ITPHelper;
40
+ })(window);
@@ -0,0 +1,7 @@
1
+ (function() {
2
+ document.addEventListener("DOMContentLoaded", function() {
3
+ var storageAccessHelper = new StorageAccessHelper();
4
+ storageAccessHelper.execute();
5
+ });
6
+ })();
7
+
@@ -0,0 +1,33 @@
1
+ (function() {
2
+ function redirect() {
3
+ var redirectTargetElement = document.getElementById("redirection-target");
4
+
5
+ if (!redirectTargetElement) {
6
+ return;
7
+ }
8
+
9
+ var targetInfo = JSON.parse(redirectTargetElement.dataset.target)
10
+
11
+ if (window.top == window.self) {
12
+ // If the current window is the 'parent', change the URL by setting location.href
13
+ window.top.location.href = targetInfo.url;
14
+ } else {
15
+ // If the current window is the 'child', change the parent's URL with postMessage
16
+ normalizedLink = document.createElement('a');
17
+ normalizedLink.href = targetInfo.url;
18
+
19
+ data = JSON.stringify({
20
+ message: 'Shopify.API.remoteRedirect',
21
+ data: {location: normalizedLink.href}
22
+ });
23
+ window.parent.postMessage(data, targetInfo.myshopifyUrl);
24
+ }
25
+ }
26
+
27
+ document.addEventListener("DOMContentLoaded", redirect);
28
+
29
+ // In the turbolinks context, neither DOMContentLoaded nor turbolinks:load
30
+ // consistently fires. This ensures that we at least attempt to fire in the
31
+ // turbolinks situation as well.
32
+ redirect();
33
+ })();
@@ -0,0 +1,3 @@
1
+ //= require ./itp_helper.js
2
+ //= require ./storage_access.js
3
+ //= require ./storage_access_redirect.js
@@ -0,0 +1,121 @@
1
+ (function() {
2
+ var ACCESS_GRANTED_STATUS = 'storage_access_granted';
3
+ var ACCESS_DENIED_STATUS = 'storage_access_denied';
4
+
5
+ function StorageAccessHelper(redirectData) {
6
+ this.redirectData = redirectData;
7
+ }
8
+
9
+ StorageAccessHelper.prototype.setNormalizedLink = function(storageAccessStatus) {
10
+ return storageAccessStatus === ACCESS_GRANTED_STATUS ? this.redirectData.hasStorageAccessUrl : this.redirectData.doesNotHaveStorageAccessUrl;
11
+ }
12
+
13
+ StorageAccessHelper.prototype.redirectToAppTLD = function(storageAccessStatus) {
14
+ var normalizedLink = document.createElement('a');
15
+
16
+ normalizedLink.href = this.setNormalizedLink(storageAccessStatus);
17
+
18
+ data = JSON.stringify({
19
+ message: 'Shopify.API.remoteRedirect',
20
+ data: {
21
+ location: normalizedLink.href,
22
+ }
23
+ });
24
+ window.parent.postMessage(data, this.redirectData.myshopifyUrl);
25
+ }
26
+
27
+ StorageAccessHelper.prototype.redirectToAppsIndex = function() {
28
+ window.parent.location.href = this.redirectData.myshopifyUrl + '/admin/apps';
29
+ }
30
+
31
+ StorageAccessHelper.prototype.redirectToAppHome = function() {
32
+ window.location.href = this.redirectData.appHomeUrl;
33
+ }
34
+
35
+ StorageAccessHelper.prototype.grantedStorageAccess = function() {
36
+ try {
37
+ sessionStorage.setItem('shopify.granted_storage_access', true);
38
+ document.cookie = 'shopify.granted_storage_access=true';
39
+ this.redirectToAppHome();
40
+ } catch (error) {
41
+ console.warn('Third party cookies may be blocked.', error);
42
+ this.redirectToAppTLD(ACCESS_DENIED_STATUS);
43
+ }
44
+ }
45
+
46
+ StorageAccessHelper.prototype.handleRequestStorageAccess = function() {
47
+ return document.requestStorageAccess().then(this.grantedStorageAccess.bind(this), this.redirectToAppsIndex.bind(this, ACCESS_DENIED_STATUS));
48
+ }
49
+
50
+ StorageAccessHelper.prototype.setupRequestStorageAccess = function() {
51
+ var requestContent = document.getElementById('RequestStorageAccess');
52
+ var requestButton = document.getElementById('TriggerAllowCookiesPrompt');
53
+
54
+ requestButton.addEventListener('click', this.handleRequestStorageAccess.bind(this));
55
+ requestContent.style.display = 'block';
56
+ }
57
+
58
+ StorageAccessHelper.prototype.handleHasStorageAccess = function() {
59
+ if (sessionStorage.getItem('shopify.granted_storage_access')) {
60
+ // If app was classified by ITP and used Storage Access API to acquire access
61
+ this.redirectToAppHome();
62
+ } else {
63
+ // If app has not been classified by ITP and still has storage access
64
+ this.redirectToAppTLD(ACCESS_GRANTED_STATUS);
65
+ }
66
+ }
67
+
68
+ StorageAccessHelper.prototype.handleGetStorageAccess = function() {
69
+ if (sessionStorage.getItem('shopify.top_level_interaction')) {
70
+ // If merchant has been redirected to interact with TLD (requirement for prompting request to gain storage access)
71
+ this.setupRequestStorageAccess();
72
+ } else {
73
+ // If merchant has not been redirected to interact with TLD (requirement for prompting request to gain storage access)
74
+ this.redirectToAppTLD(ACCESS_DENIED_STATUS);
75
+ }
76
+ }
77
+
78
+ StorageAccessHelper.prototype.manageStorageAccess = function() {
79
+ return document.hasStorageAccess().then(function(hasAccess) {
80
+ if (hasAccess) {
81
+ this.handleHasStorageAccess();
82
+ } else {
83
+ this.handleGetStorageAccess();
84
+ }
85
+ }.bind(this));
86
+ }
87
+
88
+ StorageAccessHelper.prototype.execute = function() {
89
+ if (ITPHelper.prototype.canPartitionCookies()) {
90
+ this.setUpCookiePartitioning();
91
+ return;
92
+ }
93
+
94
+ if (ITPHelper.prototype.userAgentIsAffected()) {
95
+ this.manageStorageAccess();
96
+ } else {
97
+ this.grantedStorageAccess();
98
+ }
99
+ }
100
+
101
+ /* ITP 2.0 solution: handles cookie partitioning */
102
+ StorageAccessHelper.prototype.setUpHelper = function() {
103
+ return new ITPHelper({redirectUrl: window.shopOrigin + "/admin/apps/" + window.apiKey});
104
+ }
105
+
106
+ StorageAccessHelper.prototype.setCookieAndRedirect = function() {
107
+ document.cookie = "shopify.cookies_persist=true";
108
+ var helper = this.setUpHelper();
109
+ helper.redirect();
110
+ }
111
+
112
+ StorageAccessHelper.prototype.setUpCookiePartitioning = function() {
113
+ var itpContent = document.getElementById('CookiePartitionPrompt');
114
+ itpContent.style.display = 'block';
115
+
116
+ var button = document.getElementById('AcceptCookies');
117
+ button.addEventListener('click', this.setCookieAndRedirect.bind(this));
118
+ }
119
+
120
+ this.StorageAccessHelper = StorageAccessHelper;
121
+ })(window);
@@ -0,0 +1,17 @@
1
+ (function() {
2
+ function redirect() {
3
+ var redirectTargetElement = document.getElementById("redirection-target");
4
+
5
+ var targetInfo = JSON.parse(redirectTargetElement.dataset.target)
6
+
7
+ if (window.top == window.self) {
8
+ // If the current window is the 'parent', change the URL by setting location.href
9
+ window.top.location.href = targetInfo.hasStorageAccessUrl;
10
+ } else {
11
+ var storageAccessHelper = new StorageAccessHelper(targetInfo);
12
+ storageAccessHelper.execute();
13
+ }
14
+ }
15
+
16
+ document.addEventListener("DOMContentLoaded", redirect);
17
+ })();
@@ -0,0 +1,2 @@
1
+ //= require ./itp_helper.js
2
+ //= require ./top_level_interaction.js
@@ -0,0 +1,11 @@
1
+ (function() {
2
+ function setUpTopLevelInteraction() {
3
+ var TopLevelInteraction = new ITPHelper({
4
+ redirectUrl: window.redirectUrl,
5
+ });
6
+
7
+ TopLevelInteraction.execute();
8
+ }
9
+
10
+ document.addEventListener("DOMContentLoaded", setUpTopLevelInteraction);
11
+ })();
@@ -1,12 +1,11 @@
1
1
  module ShopifyApp
2
- class AuthenticatedController < ApplicationController
2
+ class AuthenticatedController < ActionController::Base
3
3
  include ShopifyApp::Localization
4
4
  include ShopifyApp::LoginProtection
5
+ include ShopifyApp::EmbeddedApp
5
6
 
6
- before_action :set_locale
7
+ protect_from_forgery with: :exception
7
8
  before_action :login_again_if_different_shop
8
9
  around_action :shopify_session
9
-
10
- layout ShopifyApp.configuration.embedded_app? ? 'embedded_app' : 'application'
11
10
  end
12
11
  end
@@ -1,19 +1,9 @@
1
- module ShopifyApp
2
- module SessionsConcern
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- include ShopifyApp::LoginProtection
7
- layout false, only: :new
8
- end
1
+ # frozen_string_literal: true
9
2
 
10
- def new
11
- authenticate if sanitized_shop_name.present?
12
- end
13
-
14
- def create
15
- authenticate
16
- end
3
+ module ShopifyApp
4
+ # Performs login after OAuth completes
5
+ class CallbackController < ActionController::Base
6
+ include ShopifyApp::LoginProtection
17
7
 
18
8
  def callback
19
9
  if auth_hash
@@ -29,27 +19,11 @@ module ShopifyApp
29
19
  end
30
20
  end
31
21
 
32
- def destroy
33
- session[:shopify] = nil
34
- session[:shopify_domain] = nil
35
- flash[:notice] = I18n.t('.logged_out')
36
- redirect_to login_url
37
- end
38
-
39
- protected
40
-
41
- def authenticate
42
- if sanitized_shop_name.present?
43
- fullpage_redirect_to "#{main_app.root_path}auth/shopify?shop=#{sanitized_shop_name}"
44
- else
45
- redirect_to return_address
46
- end
47
- end
22
+ private
48
23
 
49
24
  def login_shop
50
- sess = ShopifyAPI::Session.new(shop_name, token)
51
- session[:shopify] = ShopifyApp::SessionRepository.store(sess)
52
- session[:shopify_domain] = shop_name
25
+ reset_session_options
26
+ set_shopify_session
53
27
  end
54
28
 
55
29
  def auth_hash
@@ -60,10 +34,29 @@ module ShopifyApp
60
34
  auth_hash.uid
61
35
  end
62
36
 
37
+ def associated_user
38
+ return unless auth_hash['extra'].present?
39
+
40
+ auth_hash['extra']['associated_user']
41
+ end
42
+
63
43
  def token
64
44
  auth_hash['credentials']['token']
65
45
  end
66
46
 
47
+ def reset_session_options
48
+ request.session_options[:renew] = true
49
+ session.delete(:_csrf_token)
50
+ end
51
+
52
+ def set_shopify_session
53
+ session_store = ShopifyAPI::Session.new(shop_name, token)
54
+
55
+ session[:shopify] = ShopifyApp::SessionRepository.store(session_store)
56
+ session[:shopify_domain] = shop_name
57
+ session[:shopify_user] = associated_user
58
+ end
59
+
67
60
  def install_webhooks
68
61
  return unless ShopifyApp.configuration.has_webhooks?
69
62
 
@@ -84,10 +77,6 @@ module ShopifyApp
84
77
  )
85
78
  end
86
79
 
87
- def return_address
88
- session.delete(:return_to) || main_app.root_url
89
- end
90
-
91
80
  def perform_after_authenticate_job
92
81
  config = ShopifyApp.configuration.after_authenticate_job
93
82
 
@@ -1,5 +1,123 @@
1
1
  module ShopifyApp
2
- class SessionsController < ApplicationController
3
- include ShopifyApp::SessionsConcern
2
+ class SessionsController < ActionController::Base
3
+ include ShopifyApp::LoginProtection
4
+
5
+ layout false, only: :new
6
+ after_action only: [:new, :create] do |controller|
7
+ controller.response.headers.except!('X-Frame-Options')
8
+ end
9
+
10
+ def new
11
+ authenticate if sanitized_shop_name.present?
12
+ end
13
+
14
+ def create
15
+ authenticate
16
+ end
17
+
18
+ def enable_cookies
19
+ validate_shop
20
+ end
21
+
22
+ def top_level_interaction
23
+ @url = login_url(top_level: true)
24
+ validate_shop
25
+ end
26
+
27
+ def granted_storage_access
28
+ return unless validate_shop
29
+
30
+ session['shopify.granted_storage_access'] = true
31
+
32
+ params = { shop: @shop }
33
+ redirect_to "#{ShopifyApp.configuration.root_url}?#{params.to_query}"
34
+ end
35
+
36
+ def destroy
37
+ reset_session
38
+ flash[:notice] = I18n.t('.logged_out')
39
+ redirect_to login_url
40
+ end
41
+
42
+ private
43
+
44
+ def authenticate
45
+ return render_invalid_shop_error unless sanitized_shop_name.present?
46
+ session['shopify.omniauth_params'] = { shop: sanitized_shop_name }
47
+
48
+ if user_agent_can_partition_cookies
49
+ authenticate_with_partitioning
50
+ else
51
+ authenticate_normally
52
+ end
53
+ end
54
+
55
+ def authenticate_normally
56
+ if request_storage_access?
57
+ redirect_to_request_storage_access
58
+ elsif authenticate_in_context?
59
+ authenticate_in_context
60
+ else
61
+ authenticate_at_top_level
62
+ end
63
+ end
64
+
65
+ def authenticate_with_partitioning
66
+ if session['shopify.cookies_persist']
67
+ clear_top_level_oauth_cookie
68
+ authenticate_in_context
69
+ else
70
+ set_top_level_oauth_cookie
71
+ fullpage_redirect_to enable_cookies_path(shop: sanitized_shop_name)
72
+ end
73
+ end
74
+
75
+ def validate_shop
76
+ @shop = sanitized_shop_name
77
+ unless @shop
78
+ render_invalid_shop_error
79
+ return false
80
+ end
81
+
82
+ true
83
+ end
84
+
85
+ def render_invalid_shop_error
86
+ flash[:error] = I18n.t('invalid_shop_url')
87
+ redirect_to return_address
88
+ end
89
+
90
+ def authenticate_in_context
91
+ redirect_to "#{main_app.root_path}auth/shopify"
92
+ end
93
+
94
+ def authenticate_at_top_level
95
+ fullpage_redirect_to login_url(top_level: true)
96
+ end
97
+
98
+ def authenticate_in_context?
99
+ return true unless ShopifyApp.configuration.embedded_app?
100
+ params[:top_level]
101
+ end
102
+
103
+ def request_storage_access?
104
+ return false unless ShopifyApp.configuration.embedded_app?
105
+ return false if params[:top_level]
106
+ return false if user_agent_is_mobile
107
+ return false if user_agent_is_pos
108
+
109
+ !session['shopify.granted_storage_access']
110
+ end
111
+
112
+ def redirect_to_request_storage_access
113
+ render :request_storage_access, layout: false, locals: {
114
+ does_not_have_storage_access_url: top_level_interaction_path(
115
+ shop: sanitized_shop_name
116
+ ),
117
+ has_storage_access_url: login_url(top_level: true),
118
+ app_home_url: granted_storage_access_path(shop: sanitized_shop_name),
119
+ current_shopify_domain: current_shopify_domain
120
+ }
121
+ end
4
122
  end
5
123
  end