shopify_app 11.5.0 → 11.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ba7612b4db7acb35c0fa91209e7b4421f90cefa6b95d52b433218e9be5a8703
4
- data.tar.gz: 9db8d74d1f2bebd2b4fe8856bb8c2d0a3e7108cfb5a940521a70ca67b1f6e1fe
3
+ metadata.gz: 1f2c7003fc52f7cdca6ab2ecd68fd087aee28e63e8bfbdc59ea7ca82886f28b8
4
+ data.tar.gz: b967b29d2122d732af04ef1aeb3fcf814fe53fd5103b124009bfad0daf2d298b
5
5
  SHA512:
6
- metadata.gz: 5b73cda40e6980ab59c5f5d40bcb09c93cfeb7e0fcfd8ff8cd953509e1d43eb45073f80e987aea8e7f585c28f50328613e5956d4d1de9e264908e3fc0265d670
7
- data.tar.gz: 349bbdfea89e30efd696f50572d09af4e421caa8a3ce89f539e5b1a05b956c0b35af1651482fc20bfdfc7d451874ffebecf15ed4ee86bb9bb885cab358a1d707
6
+ metadata.gz: 325bc337b2be96e0cd91250ee19ddbed0ac34baf2c0bcea995f4b78048738e9a3d638e95334b55bb28e3350eb20365d1f9f2fcfe698356d338e2551797a7877c
7
+ data.tar.gz: 7781e846d38666203e63eb6d17f182cea70a9011a5c5dec6b3b0dc540ae5473a21ae8f13fb82719435691b87e14c4981135d4f4e984e09a34cbd81316e89996a
@@ -1,3 +1,7 @@
1
+ 11.5.1
2
+ -----
3
+ * Revert per-user token support temporarily
4
+
1
5
  11.5.0
2
6
  -----
3
7
  * Modularizes durable session storage
data/README.md CHANGED
@@ -12,35 +12,61 @@ Shopify Application Rails engine and generator
12
12
 
13
13
  Table of Contents
14
14
  -----------------
15
- - [Introduction](#introduction)
16
- - [Becoming a Shopify App Developer](#becoming-a-shopify-app-developer)
17
- - [Installation](#installation)
18
- - [Generators](#generators)
19
- - [Mounting the Engine](#mounting-the-engine)
20
- - [Authentication](#authentication)
21
- - [WebhooksManager](#webhooksmanager)
22
- - [ScripttagsManager](#scripttagsmanager)
23
- - [RotateShopifyTokenJob](#rotateshopifytokenjob)
24
- - [App Tunneling](#app-tunneling)
25
- - [AppProxyVerification](#appproxyverification)
26
- - [Troubleshooting](#troubleshooting)
27
- - [Testing an embedded app outside the Shopify admin](#testing-an-embedded-app-outside-the-shopify-admin)
28
- - [Questions or problems?](#questions-or-problems-)
29
- - [Rails 6 Compatibility](#rails-6-compatibility)
30
- - [Upgrading from 8.6 to 9.0.0](#upgrading-from-86-to-900)
31
-
32
- Introduction
15
+ * [**Description**](#description)
16
+ * [**Quickstart**](#quickstart)
17
+ * [**Becoming a Shopify App Developer**](#becoming-a-shopify-app-developer)
18
+ * [**App Tunneling**](#app-tunneling)
19
+ * [**Installation**](#installation)
20
+ * [Rails Compatibility](#rails-compatibility)
21
+ * [**Generators**](#generators)
22
+ * [Default Generator](#default-generator)
23
+ * [Install Generator](#install-generator)
24
+ * [Shop Model Generator](#shop-model-generator)
25
+ * [Home Controller Generator](#home-controller-generator)
26
+ * [App Proxy Controller Generator](#app-proxy-controller-generator)
27
+ * [Controllers, Routes and Views](#controllers-routes-and-views)
28
+ * [**Mounting the Engine**](#mounting-the-engine)
29
+ * [**WebhooksManager**](#webhooksmanager)
30
+ * [**ScripttagsManager**](#scripttagsmanager)
31
+ * [**AfterAuthenticate Job**](#afterauthenticate-job)
32
+ * [**ShopifyApp::SessionRepository**](#shopifyappsessionrepository)
33
+ * [**Authenticated**](#authenticated)
34
+ * [**AppProxyVerification**](#appproxyverification)
35
+ * [Recommended Usage](#recommended-usage)
36
+ * [**Upgrading from 8.6 to 9.0.0**](#upgrading-from-86-to-900)
37
+ * [**Troubleshooting**](#troubleshooting)
38
+ * [Generator shopify_app:install hangs](#generator-shopify_appinstall-hangs)
39
+ * [**Testing an embedded app outside the Shopify admin**](#testing-an-embedded-app-outside-the-shopify-admin)
40
+ * [**Questions or problems?**](#questions-or-problems)
41
+
42
+
43
+ Description
33
44
  -----------
34
45
  This gem includes a Rails Engine and generators for writing Rails applications using the Shopify API. The Engine provides a SessionsController and all the required code for authenticating with a shop via Oauth (other authentication methods are not supported).
35
46
 
36
47
  *Note: It's recommended to use this on a new Rails project, so that the generator won't overwrite/delete some of your files.*
37
48
 
49
+
50
+ Quickstart
51
+ ----------
52
+
38
53
  Check out this screencast on how to create and deploy a new Shopify App to Heroku in 5 minutes:
39
54
 
40
55
  [https://www.youtube.com/watch?v=yGxeoAHlQOg](https://www.youtube.com/watch?v=yGxeoAHlQOg)
41
56
 
42
57
  Or if you prefer text instructions the steps in the video are written out [here](https://github.com/Shopify/shopify_app/blob/master/docs/Quickstart.md)
43
58
 
59
+ App Tunneling
60
+ -------------
61
+
62
+ Your local app needs to be accessible from the public Internet in order to install it on a shop, use the [App Proxy Controller](#app-proxy-controller-generator) or receive Webhooks. Use a tunneling service like [ngrok](https://ngrok.com/), [Forward](https://forwardhq.com/), [Beeceptor](https://beeceptor.com/), [Mockbin](http://mockbin.org/), [Hookbin](https://hookbin.com/), etc.
63
+
64
+ For example with [ngrok](https://ngrok.com/), run this command to set up proxying to Rails' default port:
65
+
66
+ ```sh
67
+ ngrok http 3000
68
+ ```
69
+
44
70
  Becoming a Shopify App Developer
45
71
  --------------------------------
46
72
  If you don't have a Shopify Partner account yet head over to http://shopify.com/partners to create one, you'll need it before you can start developing apps.
@@ -80,7 +106,7 @@ The default generator will run the `install`, `shop`, and `home_controller` gene
80
106
  $ rails generate shopify_app
81
107
  ```
82
108
 
83
- After running the generator, you will need to run `rails db:migrate` to add tables to your database. You can start your app with `bundle exec rails server` and install your app by visiting localhost.
109
+ After running the generator, you will need to run `rake db:migrate` to add tables to your database. You can start your app with `bundle exec rails server` and install your app by visiting localhost.
84
110
 
85
111
  ### API Keys
86
112
 
@@ -117,6 +143,17 @@ The generator adds ShopifyApp and the required initializers to the host Rails ap
117
143
  After running the `install` generator, you can start your app with `bundle exec rails server` and install your app by visiting localhost.
118
144
 
119
145
 
146
+ ### Shop Model Generator
147
+
148
+ ```sh
149
+ $ rails generate shopify_app:shop_model
150
+ ```
151
+
152
+ The `install` generator doesn't create any database tables or models for you. If you are starting a new app its quite likely that you will want a shops table and model to store the tokens when your app is installed (most of our internally developed apps do!). This generator creates a shop model and a migration. This model includes the `ShopifyApp::SessionStorage` concern which adds two methods to make it compatible as a `SessionRepository`. After running this generator you'll notice the `session_repository` in your `config/initializers/shopify_app.rb` will be set to the `Shop` model. This means that internally ShopifyApp will try and load tokens from this model.
153
+
154
+ *Note that you will need to run rake db:migrate after this generator*
155
+
156
+
120
157
  ### Home Controller Generator
121
158
 
122
159
  ```sh
@@ -208,82 +245,21 @@ ShopifyApp.configure do |config|
208
245
  end
209
246
  ```
210
247
 
211
- Authentication
212
- --------------
213
-
214
- ### ShopifyApp::SessionRepository
215
-
216
- `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)` which stores the session and returns a unique identifier and `self.retrieve(id)` which returns a `ShopifyAPI::Session` for the passed id. See either the `ShopifyApp::InMemorySessionStore` class or the `ShopifyApp::SessionStorage` concern for details.
217
-
218
- If you only run the install generator then by default you will have an in memory store but it **won't work** on multi-server environments including Heroku. For multi-server environments, implement one of the following token-storage strategies.
219
-
220
- #### Shop-based token storage
221
- Storing tokens on the store model means that any user login associated to the store will have equal access levels to whatever the original user granted the app.
222
- ```sh
223
- $ rails generate shopify_app:shop_model
224
- ```
225
- This will generate a shop model which will be the storage for the tokens necessary for authentication.
226
-
227
- #### User-based token storage
228
- A more granular control over level of access per user on an app might be necessary, to which the shop-based token strategy is not sufficient. Shopify supports a user-based token storage strategy where a unique token to each user can be managed.
229
- ```sh
230
- $ rails generate shopify_app:user_model
231
- ```
232
- This will generate a user model which will be the storage for the tokens necessary for authentication.
233
-
234
- The current Shopify user will be stored in the rails session at `session[:shopify_user]`
235
-
236
- This will change the type of token that Shopify returns and it will only be valid for a short time. Read more about `Online access` [here](https://help.shopify.com/api/getting-started/authentication/oauth). Note that this means you won't be able to use this token to respond to Webhooks.
237
-
238
- #### Migrating from shop-based to user-based token strategy
239
- After running the generator, ensure that configuration settings are successfully changed:
248
+ Per User Authentication
249
+ -----------------------
250
+ To enable per user authentication you need to update the `omniauth.rb` initializer:
240
251
 
241
252
  ```ruby
242
- # In the `omniauth.rb` initializer:
243
253
  provider :shopify,
244
254
  ShopifyApp.configuration.api_key,
245
255
  ShopifyApp.configuration.secret,
246
256
  scope: ShopifyApp.configuration.scope,
247
257
  per_user_permissions: true
248
-
249
- # In the `shopify_app.rb` initializer:
250
- config.session_repository = User
251
- config.per_user_tokens = true
252
- ```
253
-
254
- ### Authenticated
255
-
256
- The engine provides a `ShopifyApp::Authenticated` concern which should be included in any controller that is intended to be behind Shopify OAuth. It adds `before_action`s to ensure that the user is authenticated and will redirect to the Shopify login page if not. It is best practice to include this concern in a base controller inheriting from your `ApplicationController`, from which all controllers that require Shopify authentication inherit.
257
-
258
- 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`.
259
-
260
- ### AfterAuthenticate Job
261
-
262
- 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:
263
-
264
- ```ruby
265
- ShopifyApp.configure do |config|
266
- config.after_authenticate_job = { job: "Shopify::AfterAuthenticateJob" }
267
- end
268
258
  ```
269
259
 
270
- The job can be configured as either a class or a class name string.
271
-
272
- If you need the job to run synchronously add the `inline` flag:
273
-
274
- ```ruby
275
- ShopifyApp.configure do |config|
276
- config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
277
- end
278
- ```
279
-
280
- We've also provided a generator which creates a skeleton job and updates the initializer for you:
281
-
282
- ```
283
- bin/rails g shopify_app:add_after_authenticate_job
284
- ```
260
+ The current Shopify user will be stored in the rails session at `session[:shopify_user]`
285
261
 
286
- 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.
262
+ This will change the type of token that Shopify returns and it will only be valid for a short time. Read more about `Online access` [here](https://help.shopify.com/api/getting-started/authentication/oauth). Note that this means you won't be able to use this token to respond to Webhooks.
287
263
 
288
264
 
289
265
  WebhooksManager
@@ -377,6 +353,36 @@ Scripttags are created in the same way as the Webhooks, with a background job wh
377
353
 
378
354
  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.
379
355
 
356
+ AfterAuthenticate Job
357
+ ---------------------
358
+
359
+ 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:
360
+
361
+ ```ruby
362
+ ShopifyApp.configure do |config|
363
+ config.after_authenticate_job = { job: "Shopify::AfterAuthenticateJob" }
364
+ end
365
+ ```
366
+
367
+ The job can be configured as either a class or a class name string.
368
+
369
+ If you need the job to run synchronously add the `inline` flag:
370
+
371
+ ```ruby
372
+ ShopifyApp.configure do |config|
373
+ config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
374
+ end
375
+ ```
376
+
377
+ We've also provided a generator which creates a skeleton job and updates the initializer for you:
378
+
379
+ ```
380
+ bin/rails g shopify_app:add_after_authenticate_job
381
+ ```
382
+
383
+ 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.
384
+
385
+
380
386
  RotateShopifyTokenJob
381
387
  ---------------------
382
388
 
@@ -403,16 +409,19 @@ The generated rake task will be found at `lib/tasks/shopify/rotate_shopify_token
403
409
  strategy.options[:old_client_secret] = ShopifyApp.configuration.old_secret
404
410
  ```
405
411
 
406
- App Tunneling
407
- -------------
412
+ ShopifyApp::SessionRepository
413
+ -----------------------------
408
414
 
409
- Your local app needs to be accessible from the public Internet in order to install it on a shop, use the [App Proxy Controller](#app-proxy-controller-generator) or receive Webhooks. Use a tunneling service like [ngrok](https://ngrok.com/), [Forward](https://forwardhq.com/), [Beeceptor](https://beeceptor.com/), [Mockbin](http://mockbin.org/), [Hookbin](https://hookbin.com/), etc.
415
+ `ShopifyApp::SessionRepository` allows you as a developer to define how your sessions are retrieved and stored for shops. The `SessionRepository` is configured in the `config/initializers/shopify_app.rb` file and can be set to any object that implements `self.store(shopify_session)` which stores the session and returns a unique identifier and `self.retrieve(id)` which returns a `ShopifyAPI::Session` for the passed id. See either the `ShopifyApp::InMemorySessionStore` class or the `ShopifyApp::SessionStorage` concern for examples.
410
416
 
411
- For example with [ngrok](https://ngrok.com/), run this command to set up proxying to Rails' default port:
417
+ If you only run the install generator then by default you will have an in memory store but it **won't work** on multi-server environments including Heroku. If you ran all the generators including the shop_model generator then the `Shop` model itself will be the `SessionRepository`. If you look at the implementation of the generated shop model you'll see that this gem provides a concern for the `SessionRepository`. You can use this concern on any model that responds to `shopify_domain`, `shopify_token` and `api_version`.
412
418
 
413
- ```sh
414
- ngrok http 3000
415
- ```
419
+ Authenticated
420
+ -------------
421
+
422
+ The engine provides a `ShopifyApp::Authenticated` concern which should be included in any controller that is intended to be behind Shopify OAuth. It adds `before_action`s to ensure that the user is authenticated and will redirect to the Shopify login page if not. It is best practice to include this concern in a base controller inheriting from your `ApplicationController`, from which all controllers that require Shopify authentication inherit.
423
+
424
+ 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`.
416
425
 
417
426
  AppProxyVerification
418
427
  --------------------
@@ -456,7 +465,7 @@ Questions or problems?
456
465
  - [Read the docs!](https://help.shopify.com/api/guides)
457
466
 
458
467
  Rails 6 Compatibility
459
- ---------------------
468
+ ---------------------------
460
469
 
461
470
  ### Disable Webpacker
462
471
  If you are using sprockets in rails 6 or want to generate a shopify_app without webpacker run the install task by running
@@ -8,7 +8,7 @@ module ShopifyApp
8
8
  include ShopifyApp::Localization
9
9
  include ShopifyApp::LoginProtection
10
10
  include ShopifyApp::EmbeddedApp
11
- before_action :login_again_if_different_user_or_shop
11
+ before_action :login_again_if_different_shop
12
12
  around_action :shopify_session
13
13
  end
14
14
  end
@@ -55,16 +55,10 @@ module ShopifyApp
55
55
  token: token,
56
56
  api_version: ShopifyApp.configuration.api_version
57
57
  )
58
- session[:shopify] = ShopifyApp::SessionRepository.store(session_store, user: associated_user)
58
+
59
+ session[:shopify] = ShopifyApp::SessionRepository.store(session_store)
59
60
  session[:shopify_domain] = shop_name
60
61
  session[:shopify_user] = associated_user
61
-
62
- if ShopifyApp.configuration.per_user_tokens?
63
- # Adds the user_session to the session to determine if the logged in user has changed
64
- user_session = auth_hash&.extra&.session
65
- raise IndexError, "Missing user session signature" if user_session.nil?
66
- session[:user_session] = user_session
67
- end
68
62
  end
69
63
 
70
64
  def install_webhooks
@@ -8,7 +8,7 @@ ShopifyApp.configure do |config|
8
8
  config.embedded_app = <%= embedded_app? %>
9
9
  config.after_authenticate_job = false
10
10
  config.api_version = "<%= @api_version %>"
11
- config.session_repository = ShopifyApp::InMemorySessionStore
11
+ config.session_repository = 'ShopifyApp::InMemorySessionStore'
12
12
  end
13
13
 
14
14
  # ShopifyApp::Utils.fetch_known_api_versions # Uncomment to fetch known api versions from shopify servers on boot
@@ -4,7 +4,6 @@ provider :shopify,
4
4
  ShopifyApp.configuration.api_key,
5
5
  ShopifyApp.configuration.secret,
6
6
  scope: ShopifyApp.configuration.scope,
7
- per_user_permissions: ShopifyApp.configuration.per_user_tokens,
8
7
  setup: lambda { |env|
9
8
  strategy = env['omniauth.strategy']
10
9
 
@@ -44,8 +44,6 @@ module ShopifyApp
44
44
  require 'shopify_app/managers/scripttags_manager'
45
45
 
46
46
  # session
47
- require 'shopify_app/session/storage_strategies/shop_storage_strategy'
48
- require 'shopify_app/session/storage_strategies/user_storage_strategy'
49
47
  require 'shopify_app/session/session_storage'
50
48
  require 'shopify_app/session/session_repository'
51
49
  require 'shopify_app/session/in_memory_session_store'
@@ -14,9 +14,7 @@ module ShopifyApp
14
14
  attr_accessor :webhooks
15
15
  attr_accessor :scripttags
16
16
  attr_accessor :after_authenticate_job
17
- attr_accessor :session_repository
18
- attr_accessor :per_user_tokens
19
- alias_method :per_user_tokens?, :per_user_tokens
17
+ attr_reader :session_repository
20
18
  attr_accessor :api_version
21
19
 
22
20
  # customise urls
@@ -41,7 +39,6 @@ module ShopifyApp
41
39
  @myshopify_domain = 'myshopify.com'
42
40
  @scripttags_manager_queue_name = Rails.application.config.active_job.queue_name
43
41
  @webhooks_manager_queue_name = Rails.application.config.active_job.queue_name
44
- @per_user_tokens = false
45
42
  @disable_webpacker = ENV['SHOPIFY_APP_DISABLE_WEBPACKER'].present?
46
43
  end
47
44
 
@@ -50,13 +47,8 @@ module ShopifyApp
50
47
  end
51
48
 
52
49
  def session_repository=(klass)
53
- if Rails.configuration.cache_classes
54
- ShopifyApp::SessionRepository.storage = klass
55
- else
56
- ActiveSupport::Reloader.to_prepare do
57
- ShopifyApp::SessionRepository.storage = klass
58
- end
59
- end
50
+ @session_repository = klass
51
+ ShopifyApp::SessionRepository.storage = klass
60
52
  end
61
53
 
62
54
  def has_webhooks?
@@ -66,7 +58,6 @@ module ShopifyApp
66
58
  def has_scripttags?
67
59
  scripttags.present?
68
60
  end
69
-
70
61
  end
71
62
 
72
63
  def self.configuration
@@ -27,30 +27,12 @@ module ShopifyApp
27
27
  end
28
28
 
29
29
  def shop_session
30
- if ShopifyApp.configuration.per_user_tokens?
31
- return unless session[:shopify_user]
32
- @shop_session ||= ShopifyApp::SessionRepository.retrieve(session[:shopify_user]['id'])
33
- else
34
- return unless session[:shopify]
35
- @shop_session ||= ShopifyApp::SessionRepository.retrieve(session[:shopify])
36
- end
30
+ return unless session[:shopify]
31
+ @shop_session ||= ShopifyApp::SessionRepository.retrieve(session[:shopify])
37
32
  end
38
33
 
39
- def login_again_if_different_user_or_shop
40
- if ShopifyApp.configuration.per_user_tokens?
41
- valid_session_data = session[:user_session].present? && params[:session].present? # session data was sent/stored correctly
42
- sessions_do_not_match = session[:user_session] != params[:session] # current user is different from stored user
43
-
44
- if valid_session_data && sessions_do_not_match
45
- clear_session = true
46
- end
47
- end
48
-
34
+ def login_again_if_different_shop
49
35
  if shop_session && params[:shop] && params[:shop].is_a?(String) && (shop_session.domain != params[:shop])
50
- clear_session = true
51
- end
52
-
53
- if clear_session
54
36
  clear_shop_session
55
37
  redirect_to_login
56
38
  end
@@ -78,7 +60,6 @@ module ShopifyApp
78
60
  session[:shopify] = nil
79
61
  session[:shopify_domain] = nil
80
62
  session[:shopify_user] = nil
81
- session[:user_session] = nil
82
63
  end
83
64
 
84
65
  def login_url_with_optional_shop(top_level: false)
@@ -6,7 +6,7 @@ module ShopifyApp
6
6
  repo[id]
7
7
  end
8
8
 
9
- def self.store(session, *args)
9
+ def self.store(session)
10
10
  id = SecureRandom.uuid
11
11
  repo[id] = session
12
12
  id
@@ -15,8 +15,8 @@ module ShopifyApp
15
15
  storage.retrieve(id)
16
16
  end
17
17
 
18
- def store(session, *args)
19
- storage.store(session, *args)
18
+ def store(session)
19
+ storage.store(session)
20
20
  end
21
21
 
22
22
  def storage
@@ -3,12 +3,9 @@ module ShopifyApp
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
+ validates :shopify_domain, presence: true, uniqueness: { case_sensitive: false }
6
7
  validates :shopify_token, presence: true
7
8
  validates :api_version, presence: true
8
- validates :shopify_domain, presence: true,
9
- if: Proc.new {|_| ShopifyApp.configuration.per_user_tokens? }
10
- validates :shopify_domain, presence: true, uniqueness: { case_sensitive: false },
11
- if: Proc.new {|_| !ShopifyApp.configuration.per_user_tokens? }
12
9
  end
13
10
 
14
11
  def with_shopify_session(&block)
@@ -21,19 +18,23 @@ module ShopifyApp
21
18
  end
22
19
 
23
20
  class_methods do
24
-
25
- def strategy_klass
26
- ShopifyApp.configuration.per_user_tokens? ?
27
- ShopifyApp::SessionStorage::UserStorageStrategy :
28
- ShopifyApp::SessionStorage::ShopStorageStrategy
29
- end
30
-
31
- def store(auth_session, user: nil)
32
- strategy_klass.store(auth_session, user)
21
+ def store(session)
22
+ shop = find_or_initialize_by(shopify_domain: session.domain)
23
+ shop.shopify_token = session.token
24
+ shop.save!
25
+ shop.id
33
26
  end
34
27
 
35
28
  def retrieve(id)
36
- strategy_klass.retrieve(id)
29
+ return unless id
30
+
31
+ if shop = self.find_by(id: id)
32
+ ShopifyAPI::Session.new(
33
+ domain: shop.shopify_domain,
34
+ token: shop.shopify_token,
35
+ api_version: shop.api_version
36
+ )
37
+ end
37
38
  end
38
39
  end
39
40
  end
@@ -1,3 +1,3 @@
1
1
  module ShopifyApp
2
- VERSION = '11.5.0'.freeze
2
+ VERSION = '11.5.1'.freeze
3
3
  end
@@ -2,6 +2,6 @@ audience: partner
2
2
  classification: library
3
3
  org_line: App & Partner Platform
4
4
  owners:
5
- - Shopify/platform-dev-tools-education
5
+ - Shopify/app-partner-dev-tools-education
6
6
  slack_channels:
7
7
  - dev-tools-education
@@ -18,9 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.add_development_dependency('rake')
19
19
  s.add_development_dependency('byebug')
20
20
  s.add_development_dependency('pry')
21
- s.add_development_dependency('pry-nav')
22
- s.add_development_dependency('pry-stack_explorer')
23
- s.add_development_dependency('rb-readline')
24
21
  s.add_development_dependency('sqlite3', '~> 1.4')
25
22
  s.add_development_dependency('minitest')
26
23
  s.add_development_dependency('mocha')
@@ -29,4 +26,4 @@ Gem::Specification.new do |s|
29
26
  s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(test|example)/}) }
30
27
  s.test_files = `git ls-files -- {test}/*`.split("\n")
31
28
  s.require_paths = ["lib"]
32
- end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.5.0
4
+ version: 11.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-07 00:00:00.000000000 Z
11
+ date: 2020-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: browser_sniffer
@@ -108,48 +108,6 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: pry-nav
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: pry-stack_explorer
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: rb-readline
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
111
  - !ruby/object:Gem::Dependency
154
112
  name: sqlite3
155
113
  requirement: !ruby/object:Gem::Requirement
@@ -317,10 +275,6 @@ files:
317
275
  - lib/generators/shopify_app/shop_model/templates/shop.rb
318
276
  - lib/generators/shopify_app/shop_model/templates/shops.yml
319
277
  - lib/generators/shopify_app/shopify_app_generator.rb
320
- - lib/generators/shopify_app/user_model/templates/db/migrate/create_users.erb
321
- - lib/generators/shopify_app/user_model/templates/user.rb
322
- - lib/generators/shopify_app/user_model/templates/users.yml
323
- - lib/generators/shopify_app/user_model/user_model_generator.rb
324
278
  - lib/generators/shopify_app/views/views_generator.rb
325
279
  - lib/shopify_app.rb
326
280
  - lib/shopify_app/configuration.rb
@@ -339,8 +293,6 @@ files:
339
293
  - lib/shopify_app/session/in_memory_session_store.rb
340
294
  - lib/shopify_app/session/session_repository.rb
341
295
  - lib/shopify_app/session/session_storage.rb
342
- - lib/shopify_app/session/storage_strategies/shop_storage_strategy.rb
343
- - lib/shopify_app/session/storage_strategies/user_storage_strategy.rb
344
296
  - lib/shopify_app/utils.rb
345
297
  - lib/shopify_app/version.rb
346
298
  - package-lock.json
@@ -1,16 +0,0 @@
1
- class CreateUsers < ActiveRecord::Migration[<%= rails_migration_version %>]
2
- def self.up
3
- create_table :users do |t|
4
- t.bigint :shopify_user_id, null: false
5
- t.string :shopify_domain, null: false
6
- t.string :shopify_token, null: false
7
- t.timestamps
8
- end
9
-
10
- add_index :users, :shopify_user_id, unique: true
11
- end
12
-
13
- def self.down
14
- drop_table :users
15
- end
16
- end
@@ -1,7 +0,0 @@
1
- class User < ActiveRecord::Base
2
- include ShopifyApp::SessionStorage
3
-
4
- def api_version
5
- ShopifyApp.configuration.api_version
6
- end
7
- end
@@ -1,4 +0,0 @@
1
- regular_user:
2
- shopify_domain: 'regular-shop.myshopify.com'
3
- shopify_token: 'token'
4
- shopify_user_id: 1
@@ -1,38 +0,0 @@
1
- require 'rails/generators/base'
2
- require 'rails/generators/active_record'
3
-
4
- module ShopifyApp
5
- module Generators
6
- class UserModelGenerator < Rails::Generators::Base
7
- include Rails::Generators::Migration
8
- source_root File.expand_path('../templates', __FILE__)
9
-
10
- def create_user_model
11
- copy_file 'user.rb', 'app/models/user.rb'
12
- end
13
-
14
- def create_user_migration
15
- migration_template 'db/migrate/create_users.erb', 'db/migrate/create_users.rb'
16
- end
17
-
18
- def update_shopify_app_initializer
19
- gsub_file 'config/initializers/shopify_app.rb', 'ShopifyApp::InMemorySessionStore', 'User'
20
- end
21
-
22
- def create_user_fixtures
23
- copy_file 'users.yml', 'test/fixtures/users.yml'
24
- end
25
-
26
- private
27
-
28
- def rails_migration_version
29
- Rails.version.match(/\d\.\d/)[0]
30
- end
31
-
32
- # for generating a timestamp when using `create_migration`
33
- def self.next_migration_number(dir)
34
- ActiveRecord::Generators::Base.next_migration_number(dir)
35
- end
36
- end
37
- end
38
- end
@@ -1,24 +0,0 @@
1
- module ShopifyApp
2
- module SessionStorage
3
- class ShopStorageStrategy
4
-
5
- def self.store(auth_session, *args)
6
- shop = Shop.find_or_initialize_by(shopify_domain: auth_session.domain)
7
- shop.shopify_token = auth_session.token
8
- shop.save!
9
- shop.id
10
- end
11
-
12
- def self.retrieve(id)
13
- return unless id
14
- if shop = Shop.find_by(id: id)
15
- ShopifyAPI::Session.new(
16
- domain: shop.shopify_domain,
17
- token: shop.shopify_token,
18
- api_version: shop.api_version
19
- )
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,26 +0,0 @@
1
- module ShopifyApp
2
- module SessionStorage
3
- class UserStorageStrategy
4
-
5
- def self.store(auth_session, user)
6
- user = User.find_or_initialize_by(shopify_user_id: user[:id])
7
- user.shopify_token = auth_session.token
8
- user.shopify_domain = auth_session.domain
9
- user.save!
10
- user.id
11
- end
12
-
13
- def self.retrieve(id)
14
- return unless id
15
- if user = User.find_by(shopify_user_id: id)
16
- ShopifyAPI::Session.new(
17
- domain: user.shopify_domain,
18
- token: user.shopify_token,
19
- api_version: user.api_version
20
- )
21
- end
22
- end
23
-
24
- end
25
- end
26
- end