shopify_app 7.2.0 → 8.5.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/{ISSUE_TEMPLATE.md → .github/ISSUE_TEMPLATE.md} +0 -0
- data/.github/probots.yml +2 -0
- data/.gitignore +5 -0
- data/.nvmrc +1 -0
- data/.rubocop.yml +10 -0
- data/.ruby-version +1 -0
- data/.travis.yml +24 -12
- data/CHANGELOG.md +151 -0
- data/Gemfile +2 -0
- data/README.md +167 -68
- data/app/assets/images/storage_access.svg +2 -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 +7 -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 +121 -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/shopify_app/authenticated_controller.rb +5 -2
- data/app/controllers/shopify_app/callback_controller.rb +92 -0
- data/app/controllers/shopify_app/sessions_controller.rb +120 -2
- data/app/controllers/shopify_app/webhooks_controller.rb +11 -3
- data/app/views/shopify_app/partials/_button_styles.html.erb +104 -0
- data/app/views/shopify_app/partials/_card_styles.html.erb +33 -0
- data/app/views/shopify_app/partials/_empty_state_styles.html.erb +129 -0
- data/app/views/shopify_app/partials/_layout_styles.html.erb +167 -0
- data/app/views/shopify_app/partials/_typography_styles.html.erb +35 -0
- data/app/views/shopify_app/sessions/enable_cookies.html.erb +59 -0
- data/app/views/shopify_app/sessions/new.html.erb +88 -60
- data/app/views/shopify_app/sessions/request_storage_access.html.erb +67 -0
- data/app/views/shopify_app/sessions/top_level_interaction.html.erb +63 -0
- data/app/views/shopify_app/shared/redirect.html.erb +22 -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/fr.yml +23 -0
- data/config/locales/it.yml +22 -0
- data/config/locales/ja.yml +17 -0
- data/config/locales/nl.yml +21 -0
- data/config/locales/pt-BR.yml +22 -0
- data/config/locales/zh-CN.yml +16 -0
- data/config/locales/zh-TW.yml +17 -0
- data/config/routes.rb +11 -1
- data/{QUICKSTART.md → docs/Quickstart.md} +26 -23
- data/docs/Releasing.md +18 -0
- data/docs/Troubleshooting.md +16 -0
- data/karma.conf.js +43 -0
- data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +45 -0
- data/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb +10 -0
- data/lib/generators/shopify_app/home_controller/templates/home_controller.rb +1 -0
- data/lib/generators/shopify_app/home_controller/templates/index.html.erb +14 -0
- data/lib/generators/shopify_app/home_controller/templates/shopify_app_ready_script.html.erb +1 -5
- data/lib/generators/shopify_app/install/install_generator.rb +10 -16
- data/lib/generators/shopify_app/install/templates/_flash_messages.html.erb +13 -9
- data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +1 -1
- data/lib/generators/shopify_app/install/templates/shopify_app.rb +5 -3
- data/lib/generators/shopify_app/install/templates/shopify_provider.rb +19 -4
- 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/shop_model/shop_model_generator.rb +5 -9
- 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 +0 -1
- data/lib/shopify_app/configuration.rb +27 -8
- data/lib/shopify_app/{app_proxy_verification.rb → controller_concerns/app_proxy_verification.rb} +2 -7
- data/lib/shopify_app/controller_concerns/embedded_app.rb +19 -0
- data/lib/shopify_app/controller_concerns/itp.rb +45 -0
- data/lib/shopify_app/controller_concerns/localization.rb +22 -0
- data/lib/shopify_app/controller_concerns/login_protection.rb +135 -0
- data/lib/shopify_app/{webhook_verification.rb → controller_concerns/webhook_verification.rb} +11 -12
- data/lib/shopify_app/engine.rb +10 -0
- data/lib/shopify_app/{scripttags_manager_job.rb → jobs/scripttags_manager_job.rb} +2 -2
- data/lib/shopify_app/{webhooks_manager_job.rb → jobs/webhooks_manager_job.rb} +0 -0
- data/lib/shopify_app/{scripttags_manager.rb → managers/scripttags_manager.rb} +24 -8
- data/lib/shopify_app/{webhooks_manager.rb → managers/webhooks_manager.rb} +1 -1
- data/lib/shopify_app/session/in_memory_session_store.rb +27 -0
- data/lib/shopify_app/{shopify_session_repository.rb → session/session_repository.rb} +0 -0
- data/lib/shopify_app/{session_storage.rb → session/session_storage.rb} +9 -0
- data/lib/shopify_app/utils.rb +2 -2
- data/lib/shopify_app/version.rb +1 -1
- data/lib/shopify_app.rb +21 -16
- data/package-lock.json +23 -0
- data/package.json +28 -0
- data/service.yml +7 -0
- data/shipit.rubygems.yml +2 -0
- data/shopify_app.gemspec +6 -5
- data/translation.yml +7 -0
- data/webpack.config.js +24 -0
- data/yarn.lock +4594 -0
- metadata +92 -35
- data/Gemfile.rails50 +0 -5
- data/Gemfile.ruby22 +0 -6
- data/Gemfile.ruby22.rails50 +0 -9
- data/RELEASING +0 -13
- 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/sessions_concern.rb +0 -101
- data/lib/shopify_app/shop.rb +0 -15
metadata
CHANGED
@@ -1,57 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify_app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 8.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: browser_sniffer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rails
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
33
|
+
version: 5.0.0
|
20
34
|
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
40
|
+
version: 5.0.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: shopify_api
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.
|
47
|
+
version: 4.3.5
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 4.
|
54
|
+
version: 4.3.5
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: omniauth-shopify-oauth2
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 2.1.0
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 2.1.0
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,16 +98,16 @@ dependencies:
|
|
84
98
|
name: sqlite3
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- - "
|
101
|
+
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
103
|
+
version: 1.3.6
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - "
|
108
|
+
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
110
|
+
version: 1.3.6
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: minitest
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,27 +142,62 @@ executables: []
|
|
128
142
|
extensions: []
|
129
143
|
extra_rdoc_files: []
|
130
144
|
files:
|
145
|
+
- ".babelrc"
|
146
|
+
- ".github/CODEOWNERS"
|
147
|
+
- ".github/ISSUE_TEMPLATE.md"
|
148
|
+
- ".github/probots.yml"
|
131
149
|
- ".gitignore"
|
150
|
+
- ".nvmrc"
|
151
|
+
- ".rubocop.yml"
|
152
|
+
- ".ruby-version"
|
132
153
|
- ".travis.yml"
|
133
154
|
- CHANGELOG.md
|
134
155
|
- Gemfile
|
135
|
-
- Gemfile.rails50
|
136
|
-
- Gemfile.ruby22
|
137
|
-
- Gemfile.ruby22.rails50
|
138
|
-
- ISSUE_TEMPLATE.md
|
139
156
|
- LICENSE
|
140
|
-
- QUICKSTART.md
|
141
157
|
- README.md
|
142
|
-
- RELEASING
|
143
158
|
- Rakefile
|
159
|
+
- app/assets/images/storage_access.svg
|
160
|
+
- app/assets/javascripts/shopify_app/enable_cookies.js
|
161
|
+
- app/assets/javascripts/shopify_app/itp_helper.js
|
162
|
+
- app/assets/javascripts/shopify_app/partition_cookies.js
|
163
|
+
- app/assets/javascripts/shopify_app/redirect.js
|
164
|
+
- app/assets/javascripts/shopify_app/request_storage_access.js
|
165
|
+
- app/assets/javascripts/shopify_app/storage_access.js
|
166
|
+
- app/assets/javascripts/shopify_app/storage_access_redirect.js
|
167
|
+
- app/assets/javascripts/shopify_app/top_level.js
|
168
|
+
- app/assets/javascripts/shopify_app/top_level_interaction.js
|
144
169
|
- app/controllers/shopify_app/authenticated_controller.rb
|
170
|
+
- app/controllers/shopify_app/callback_controller.rb
|
145
171
|
- app/controllers/shopify_app/sessions_controller.rb
|
146
172
|
- app/controllers/shopify_app/webhooks_controller.rb
|
173
|
+
- app/views/shopify_app/partials/_button_styles.html.erb
|
174
|
+
- app/views/shopify_app/partials/_card_styles.html.erb
|
175
|
+
- app/views/shopify_app/partials/_empty_state_styles.html.erb
|
176
|
+
- app/views/shopify_app/partials/_layout_styles.html.erb
|
177
|
+
- app/views/shopify_app/partials/_typography_styles.html.erb
|
178
|
+
- app/views/shopify_app/sessions/enable_cookies.html.erb
|
147
179
|
- app/views/shopify_app/sessions/new.html.erb
|
180
|
+
- app/views/shopify_app/sessions/request_storage_access.html.erb
|
181
|
+
- app/views/shopify_app/sessions/top_level_interaction.html.erb
|
182
|
+
- app/views/shopify_app/shared/redirect.html.erb
|
183
|
+
- config/locales/de.yml
|
148
184
|
- config/locales/en.yml
|
149
185
|
- config/locales/es.yml
|
186
|
+
- config/locales/fr.yml
|
187
|
+
- config/locales/it.yml
|
188
|
+
- config/locales/ja.yml
|
189
|
+
- config/locales/nl.yml
|
190
|
+
- config/locales/pt-BR.yml
|
191
|
+
- config/locales/zh-CN.yml
|
192
|
+
- config/locales/zh-TW.yml
|
150
193
|
- config/routes.rb
|
194
|
+
- docs/Quickstart.md
|
195
|
+
- docs/Releasing.md
|
196
|
+
- docs/Troubleshooting.md
|
151
197
|
- images/app-proxy-screenshot.png
|
198
|
+
- karma.conf.js
|
199
|
+
- lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
|
200
|
+
- lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb
|
152
201
|
- lib/generators/shopify_app/add_webhook/add_webhook_generator.rb
|
153
202
|
- lib/generators/shopify_app/add_webhook/templates/webhook_job.rb
|
154
203
|
- lib/generators/shopify_app/app_proxy_controller/app_proxy_controller_generator.rb
|
@@ -166,35 +215,43 @@ files:
|
|
166
215
|
- lib/generators/shopify_app/install/templates/omniauth.rb
|
167
216
|
- lib/generators/shopify_app/install/templates/shopify_app.rb
|
168
217
|
- lib/generators/shopify_app/install/templates/shopify_provider.rb
|
169
|
-
- lib/generators/shopify_app/
|
218
|
+
- lib/generators/shopify_app/rotate_shopify_token_job/rotate_shopify_token_job_generator.rb
|
219
|
+
- lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token.rake
|
220
|
+
- lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token_job.rb
|
170
221
|
- lib/generators/shopify_app/routes/routes_generator.rb
|
171
222
|
- lib/generators/shopify_app/routes/templates/routes.rb
|
172
223
|
- lib/generators/shopify_app/shop_model/shop_model_generator.rb
|
173
|
-
- lib/generators/shopify_app/shop_model/templates/db/migrate/create_shops.
|
224
|
+
- lib/generators/shopify_app/shop_model/templates/db/migrate/create_shops.erb
|
174
225
|
- lib/generators/shopify_app/shop_model/templates/shop.rb
|
175
|
-
- lib/generators/shopify_app/shop_model/templates/shopify_session_repository.rb
|
176
226
|
- lib/generators/shopify_app/shop_model/templates/shops.yml
|
177
227
|
- lib/generators/shopify_app/shopify_app_generator.rb
|
178
228
|
- lib/generators/shopify_app/views/views_generator.rb
|
179
229
|
- lib/shopify_app.rb
|
180
|
-
- lib/shopify_app/app_proxy_verification.rb
|
181
230
|
- lib/shopify_app/configuration.rb
|
231
|
+
- lib/shopify_app/controller_concerns/app_proxy_verification.rb
|
232
|
+
- lib/shopify_app/controller_concerns/embedded_app.rb
|
233
|
+
- lib/shopify_app/controller_concerns/itp.rb
|
234
|
+
- lib/shopify_app/controller_concerns/localization.rb
|
235
|
+
- lib/shopify_app/controller_concerns/login_protection.rb
|
236
|
+
- lib/shopify_app/controller_concerns/webhook_verification.rb
|
182
237
|
- lib/shopify_app/engine.rb
|
183
|
-
- lib/shopify_app/
|
184
|
-
- lib/shopify_app/
|
185
|
-
- lib/shopify_app/scripttags_manager.rb
|
186
|
-
- lib/shopify_app/
|
187
|
-
- lib/shopify_app/
|
188
|
-
- lib/shopify_app/
|
189
|
-
- lib/shopify_app/
|
190
|
-
- lib/shopify_app/shopify_session_repository.rb
|
238
|
+
- lib/shopify_app/jobs/scripttags_manager_job.rb
|
239
|
+
- lib/shopify_app/jobs/webhooks_manager_job.rb
|
240
|
+
- lib/shopify_app/managers/scripttags_manager.rb
|
241
|
+
- lib/shopify_app/managers/webhooks_manager.rb
|
242
|
+
- lib/shopify_app/session/in_memory_session_store.rb
|
243
|
+
- lib/shopify_app/session/session_repository.rb
|
244
|
+
- lib/shopify_app/session/session_storage.rb
|
191
245
|
- lib/shopify_app/utils.rb
|
192
246
|
- lib/shopify_app/version.rb
|
193
|
-
-
|
194
|
-
-
|
195
|
-
-
|
247
|
+
- package-lock.json
|
248
|
+
- package.json
|
249
|
+
- service.yml
|
196
250
|
- shipit.rubygems.yml
|
197
251
|
- shopify_app.gemspec
|
252
|
+
- translation.yml
|
253
|
+
- webpack.config.js
|
254
|
+
- yarn.lock
|
198
255
|
homepage:
|
199
256
|
licenses: []
|
200
257
|
metadata: {}
|
@@ -206,7 +263,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
206
263
|
requirements:
|
207
264
|
- - ">="
|
208
265
|
- !ruby/object:Gem::Version
|
209
|
-
version: 2.
|
266
|
+
version: 2.3.1
|
210
267
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
268
|
requirements:
|
212
269
|
- - ">="
|
@@ -214,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
271
|
version: '0'
|
215
272
|
requirements: []
|
216
273
|
rubyforge_project:
|
217
|
-
rubygems_version: 2.
|
274
|
+
rubygems_version: 2.7.6
|
218
275
|
signing_key:
|
219
276
|
specification_version: 4
|
220
277
|
summary: This gem is used to get quickly started with the Shopify API
|
data/Gemfile.rails50
DELETED
data/Gemfile.ruby22
DELETED
data/Gemfile.ruby22.rails50
DELETED
data/RELEASING
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
Releasing ShopifyApp
|
2
|
-
|
3
|
-
1. Check the Semantic Versioning page for info on how to version the new release: http://semver.org
|
4
|
-
2. Update the version of ShopifyApp in lib/shopify_app/version.rb
|
5
|
-
3. Add a CHANGELOG entry for the new release with the date
|
6
|
-
4. Commit the changes with a commit message like "Packaging for release X.Y.Z"
|
7
|
-
5. Tag the release with the version (Leave REV blank for HEAD or provide a SHA)
|
8
|
-
$ git tag vX.Y.Z REV
|
9
|
-
6. Push out the changes
|
10
|
-
$ git push
|
11
|
-
7. Push out the tags
|
12
|
-
$ git push --tags
|
13
|
-
8. Use Shipit to build and push the gem
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# You should replace InMemorySessionStore with what you will be using
|
2
|
-
# in Production. For example a model called "Shop":
|
3
|
-
#
|
4
|
-
# ShopifySessionRepository.storage = 'Shop'
|
5
|
-
#
|
6
|
-
# Interface to implement are self.retrieve(id) and self.store(ShopifyAPI::Session)
|
7
|
-
# Here is how you would add these functions to an ActiveRecord:
|
8
|
-
#
|
9
|
-
# class Shop < ActiveRecord::Base
|
10
|
-
# def self.store(session)
|
11
|
-
# shop = self.new(domain: session.url, token: session.token)
|
12
|
-
# shop.save!
|
13
|
-
# shop.id
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# def self.retrieve(id)
|
17
|
-
# if shop = self.where(id: id).first
|
18
|
-
# ShopifyAPI::Session.new(shop.domain, shop.token)
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
|
23
|
-
ShopifyApp::SessionRepository.storage = InMemorySessionStore
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# WARNING - This really only works for development, see README for more details
|
2
|
-
class InMemorySessionStore
|
3
|
-
class EnvironmentError < StandardError; end
|
4
|
-
|
5
|
-
def self.retrieve(id)
|
6
|
-
repo[id]
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.store(session)
|
10
|
-
id = SecureRandom.uuid
|
11
|
-
repo[id] = session
|
12
|
-
id
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.clear
|
16
|
-
@@repo = nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.repo
|
20
|
-
if Rails.env.production?
|
21
|
-
raise EnvironmentError.new("Cannot use InMemorySessionStore in a Production environment")
|
22
|
-
end
|
23
|
-
@@repo ||= {}
|
24
|
-
end
|
25
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
module ShopifyApp
|
2
|
-
module LoginProtection
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
rescue_from ActiveResource::UnauthorizedAccess, :with => :close_session
|
7
|
-
end
|
8
|
-
|
9
|
-
def shopify_session
|
10
|
-
if shop_session
|
11
|
-
begin
|
12
|
-
ShopifyAPI::Base.activate_session(shop_session)
|
13
|
-
yield
|
14
|
-
ensure
|
15
|
-
ShopifyAPI::Base.clear_session
|
16
|
-
end
|
17
|
-
else
|
18
|
-
redirect_to_login
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def shop_session
|
23
|
-
return unless session[:shopify]
|
24
|
-
@shop_session ||= ShopifyApp::SessionRepository.retrieve(session[:shopify])
|
25
|
-
end
|
26
|
-
|
27
|
-
def login_again_if_different_shop
|
28
|
-
if shop_session && params[:shop] && params[:shop].is_a?(String) && shop_session.url != params[:shop]
|
29
|
-
session[:shopify] = nil
|
30
|
-
session[:shopify_domain] = nil
|
31
|
-
redirect_to_login
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
protected
|
36
|
-
|
37
|
-
def redirect_to_login
|
38
|
-
if request.xhr?
|
39
|
-
head :unauthorized
|
40
|
-
else
|
41
|
-
session[:return_to] = request.fullpath if request.get?
|
42
|
-
redirect_to_with_fallback main_or_engine_login_url(shop: params[:shop])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def close_session
|
47
|
-
session[:shopify] = nil
|
48
|
-
session[:shopify_domain] = nil
|
49
|
-
redirect_to_with_fallback main_or_engine_login_url(shop: params[:shop])
|
50
|
-
end
|
51
|
-
|
52
|
-
def main_or_engine_login_url(params = {})
|
53
|
-
main_app.login_url(params)
|
54
|
-
rescue NoMethodError => e
|
55
|
-
shopify_app.login_url(params)
|
56
|
-
end
|
57
|
-
|
58
|
-
def redirect_to_with_fallback(url)
|
59
|
-
url_json = url.to_json
|
60
|
-
url_json_no_quotes = url_json.gsub(/\A"|"\Z/, '')
|
61
|
-
|
62
|
-
render inline: %Q(
|
63
|
-
<!DOCTYPE html>
|
64
|
-
<html lang="en">
|
65
|
-
<head>
|
66
|
-
<meta charset="utf-8" />
|
67
|
-
<title>Redirecting…</title>
|
68
|
-
<script type="text/javascript">
|
69
|
-
window.location.href = #{url_json};
|
70
|
-
</script>
|
71
|
-
</head>
|
72
|
-
<body>
|
73
|
-
</body>
|
74
|
-
</html>
|
75
|
-
), status: 302, location: url
|
76
|
-
end
|
77
|
-
|
78
|
-
def fullpage_redirect_to(url)
|
79
|
-
url_json = url.to_json
|
80
|
-
url_json_no_quotes = url_json.gsub(/\A"|"\Z/, '')
|
81
|
-
|
82
|
-
if ShopifyApp.configuration.embedded_app?
|
83
|
-
render inline: %Q(
|
84
|
-
<!DOCTYPE html>
|
85
|
-
<html lang="en">
|
86
|
-
<head>
|
87
|
-
<meta charset="utf-8" />
|
88
|
-
<base target="_top">
|
89
|
-
<title>Redirecting…</title>
|
90
|
-
<script type="text/javascript">
|
91
|
-
window.top.location.href = #{url_json};
|
92
|
-
</script>
|
93
|
-
</head>
|
94
|
-
<body>
|
95
|
-
</body>
|
96
|
-
</html>
|
97
|
-
)
|
98
|
-
else
|
99
|
-
redirect_to_with_fallback url
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,101 +0,0 @@
|
|
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
|
9
|
-
|
10
|
-
def new
|
11
|
-
authenticate if params[:shop].present?
|
12
|
-
end
|
13
|
-
|
14
|
-
def create
|
15
|
-
authenticate
|
16
|
-
end
|
17
|
-
|
18
|
-
def callback
|
19
|
-
if auth_hash
|
20
|
-
login_shop
|
21
|
-
install_webhooks
|
22
|
-
install_scripttags
|
23
|
-
|
24
|
-
flash[:notice] = I18n.t('.logged_in')
|
25
|
-
redirect_to_with_fallback return_address
|
26
|
-
else
|
27
|
-
flash[:error] = I18n.t('could_not_log_in')
|
28
|
-
redirect_to_with_fallback login_url
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def destroy
|
33
|
-
session[:shopify] = nil
|
34
|
-
session[:shopify_domain] = nil
|
35
|
-
flash[:notice] = I18n.t('.logged_out')
|
36
|
-
redirect_to_with_fallback login_url
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
def authenticate
|
42
|
-
if shop_name = sanitize_shop_param(params)
|
43
|
-
fullpage_redirect_to "#{main_app.root_path}auth/shopify?shop=#{shop_name}"
|
44
|
-
else
|
45
|
-
redirect_to_with_fallback return_address
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def login_shop
|
50
|
-
sess = ShopifyAPI::Session.new(shop_name, token)
|
51
|
-
session[:shopify] = ShopifyApp::SessionRepository.store(sess)
|
52
|
-
session[:shopify_domain] = shop_name
|
53
|
-
end
|
54
|
-
|
55
|
-
def auth_hash
|
56
|
-
request.env['omniauth.auth']
|
57
|
-
end
|
58
|
-
|
59
|
-
def shop_name
|
60
|
-
auth_hash.uid
|
61
|
-
end
|
62
|
-
|
63
|
-
def token
|
64
|
-
auth_hash['credentials']['token']
|
65
|
-
end
|
66
|
-
|
67
|
-
def install_webhooks
|
68
|
-
return unless ShopifyApp.configuration.has_webhooks?
|
69
|
-
|
70
|
-
WebhooksManager.queue(
|
71
|
-
shop_name,
|
72
|
-
token,
|
73
|
-
ShopifyApp.configuration.webhooks
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
def install_scripttags
|
78
|
-
return unless ShopifyApp.configuration.has_scripttags?
|
79
|
-
|
80
|
-
ScripttagsManager.queue(
|
81
|
-
shop_name,
|
82
|
-
token,
|
83
|
-
ShopifyApp.configuration.scripttags
|
84
|
-
)
|
85
|
-
end
|
86
|
-
|
87
|
-
def return_address
|
88
|
-
session.delete(:return_to) || main_app.root_url
|
89
|
-
end
|
90
|
-
|
91
|
-
def sanitized_shop_name
|
92
|
-
@sanitized_shop_name ||= sanitize_shop_param(params)
|
93
|
-
end
|
94
|
-
|
95
|
-
def sanitize_shop_param(params)
|
96
|
-
return unless params[:shop].present?
|
97
|
-
ShopifyApp::Utils.sanitize_shop_domain(params[:shop])
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
data/lib/shopify_app/shop.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module ShopifyApp
|
2
|
-
module Shop
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
validates :shopify_domain, presence: true, uniqueness: true
|
7
|
-
validates :shopify_token, presence: true
|
8
|
-
end
|
9
|
-
|
10
|
-
def with_shopify_session(&block)
|
11
|
-
ShopifyAPI::Session.temp(shopify_domain, shopify_token, &block)
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|