shopify_app 16.0.0 → 16.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +18 -2
- data/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb +22 -0
- data/docs/Releasing.md +1 -0
- data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +16 -7
- data/lib/generators/shopify_app/home_controller/templates/index.html.erb +10 -10
- data/lib/generators/shopify_app/install/install_generator.rb +5 -0
- data/lib/generators/shopify_app/install/templates/shopify_app.rb.tt +2 -1
- data/lib/shopify_app/configuration.rb +3 -0
- data/lib/shopify_app/controller_concerns/login_protection.rb +2 -0
- data/lib/shopify_app/version.rb +1 -1
- data/package.json +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44ec6da287b58bdae2e84213de7ef0780078bd09c7c25558b75e738e7b1fe8ae
|
4
|
+
data.tar.gz: fc2e72d9c007933a42c45f286b259b2a27a425b0174aadd9095f140d2707922a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf8d2e8fda1d93bf9bee47491662d751be025f2f3dd80cf0e6bc92fc7a5577481dcf78fcba8e9dee1c03c0b5ebf34c686e062eb03313de9679ca3056f675b669
|
7
|
+
data.tar.gz: a71980adc7d070ba469e1fe1a15b69ebbadf8f4f871b3fb2ccc32d989df85cbb702df5101c5cc57b253416693530cd412011e227dc5aa9a24c96e2efddcdb506
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
16.1.0
|
2
|
+
------
|
3
|
+
* Use Session Token auth strategy by default for new embedded apps [#1111](https://github.com/Shopify/shopify_app/pull/1111)
|
4
|
+
* Create optional `EnsureAuthenticatedLinks` concern to authenticate deep links using Turbolinks [#1118](https://github.com/Shopify/shopify_app/pull/1118)
|
5
|
+
|
1
6
|
16.0.0
|
2
7
|
------
|
3
8
|
* Update all `html.erb` and `css` files to correspond with updated store admin design language [#1102](https://github.com/Shopify/shopify_app/pull/1102)
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -107,6 +107,7 @@ Options include:
|
|
107
107
|
(e.g. `--scope read_products, write_orders, write_products` or `--scope "read_products, write_orders, write_products"`)
|
108
108
|
For more information, refer to the [docs](http://docs.shopify.com/api/tutorials/oauth).
|
109
109
|
* `embedded` - the default is to generate an [embedded app](http://docs.shopify.com/embedded-app-sdk), if you want a legacy non-embedded app then set this to false, `--embedded false`
|
110
|
+
* __[Not recommended for embedded apps]__ `with-cookie-authentication` - sets up the authentication strategy of the app to use cookies. By default, it uses JWT based session tokens.
|
110
111
|
|
111
112
|
You can update any of these settings later on easily; the arguments are simply for convenience.
|
112
113
|
|
@@ -121,10 +122,10 @@ After running the `install` generator, you can start your app with `bundle exec
|
|
121
122
|
$ rails generate shopify_app:home_controller
|
122
123
|
```
|
123
124
|
|
124
|
-
This generator creates an example home controller and view which fetches and displays products using the Shopify API.
|
125
|
+
This generator creates an example home controller and view which fetches and displays products using the Shopify API. By default, this generator creates an unauthenticated home_controller and a sample protected products_controller.
|
125
126
|
|
126
127
|
Options include:
|
127
|
-
* __[
|
128
|
+
* __[Not recommended for embedded apps]__ `with-cookie-authentication` - This flag generates an authenticated home_controller, where the authentication strategy relies on cookies. By default, this generator creates an unauthenticated home_controller and protected sample products_controller.
|
128
129
|
|
129
130
|
### Products Controller Generator
|
130
131
|
|
@@ -279,6 +280,21 @@ The engine provides a `ShopifyApp::Authenticated` concern which should be includ
|
|
279
280
|
|
280
281
|
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`.
|
281
282
|
|
283
|
+
### EnsureAuthenticatedLinks
|
284
|
+
|
285
|
+
The `ShopifyApp::EnsureAuthenticatedLinks` concern helps authenticate users that access protected pages of your app directly.
|
286
|
+
|
287
|
+
Include this concern in your app's `AuthenticatedController` if your app uses session tokens with [Turbolinks](https://shopify.dev/tutorials/authenticate-server-side-rendered-apps-with-session-tokens-app-bridge-turbolinks). It adds a `before_action` filter that detects whether a session token is present or not. If a session is not found, the user is redirected to your app's splash page path (`root_path`) along with `return_to` and `shop` parameters.
|
288
|
+
|
289
|
+
Example `AuthenticatedController`:
|
290
|
+
|
291
|
+
```rb
|
292
|
+
class AuthenticatedController < ApplicationController
|
293
|
+
include ShopifyApp::EnsureAuthenticatedLinks
|
294
|
+
include ShopifyApp::Authenticated
|
295
|
+
end
|
296
|
+
```
|
297
|
+
|
282
298
|
### AfterAuthenticate Job
|
283
299
|
|
284
300
|
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:
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShopifyApp
|
4
|
+
module EnsureAuthenticatedLinks
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
before_action :redirect_to_splash_page, if: :missing_expected_jwt?
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def redirect_to_splash_page
|
14
|
+
splash_page_path = root_path(return_to: request.fullpath, shop: current_shopify_domain)
|
15
|
+
redirect_to(splash_page_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def missing_expected_jwt?
|
19
|
+
jwt_shopify_domain.blank?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/docs/Releasing.md
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
1. Create a pull request with the following changes:
|
6
6
|
- Update the version of ShopifyApp in lib/shopify_app/version.rb
|
7
7
|
- Update the version of shopify_app in package.json
|
8
|
+
- Run `bundle` to update `Gemfile.lock`
|
8
9
|
- Add a CHANGELOG entry for the new release with the date
|
9
10
|
- Change the title of the PR to something like: "Packaging for release X.Y.Z"
|
10
11
|
1. Merge your pull request
|
@@ -6,16 +6,15 @@ module ShopifyApp
|
|
6
6
|
class HomeControllerGenerator < Rails::Generators::Base
|
7
7
|
source_root File.expand_path('../templates', __FILE__)
|
8
8
|
|
9
|
-
class_option :
|
9
|
+
class_option :with_cookie_authentication, type: :boolean, default: false
|
10
|
+
class_option :embedded, type: :string, default: 'true'
|
10
11
|
|
11
12
|
def create_home_controller
|
12
|
-
@with_session_token = options['with_session_token']
|
13
|
-
|
14
13
|
template(home_controller_template, 'app/controllers/home_controller.rb')
|
15
14
|
end
|
16
15
|
|
17
16
|
def create_products_controller
|
18
|
-
generate("shopify_app:products_controller")
|
17
|
+
generate("shopify_app:products_controller") unless with_cookie_authentication?
|
19
18
|
end
|
20
19
|
|
21
20
|
def create_home_index_view
|
@@ -28,16 +27,26 @@ module ShopifyApp
|
|
28
27
|
|
29
28
|
private
|
30
29
|
|
30
|
+
def embedded?
|
31
|
+
options['embedded'] == 'true'
|
32
|
+
end
|
33
|
+
|
31
34
|
def embedded_app?
|
32
35
|
ShopifyApp.configuration.embedded_app?
|
33
36
|
end
|
34
37
|
|
35
|
-
def
|
36
|
-
|
38
|
+
def with_cookie_authentication?
|
39
|
+
options['with_cookie_authentication']
|
37
40
|
end
|
38
41
|
|
39
42
|
def home_controller_template
|
40
|
-
|
43
|
+
return 'unauthenticated_home_controller.rb' unless authenticated_home_controller_required?
|
44
|
+
|
45
|
+
'home_controller.rb'
|
46
|
+
end
|
47
|
+
|
48
|
+
def authenticated_home_controller_required?
|
49
|
+
with_cookie_authentication? || !embedded? || !embedded_app?
|
41
50
|
end
|
42
51
|
end
|
43
52
|
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
rel="stylesheet"
|
8
8
|
href="https://unpkg.com/@shopify/polaris@4.25.0/styles.min.css"
|
9
9
|
/>
|
10
|
-
<%
|
10
|
+
<% unless with_cookie_authentication? %> <script>
|
11
11
|
document.addEventListener("DOMContentLoaded", async function() {
|
12
12
|
var SessionToken = window["app-bridge"].actions.SessionToken
|
13
13
|
var app = window.app;
|
@@ -47,7 +47,7 @@
|
|
47
47
|
<% end %> </head>
|
48
48
|
<body>
|
49
49
|
<h2>Products</h2>
|
50
|
-
<%
|
50
|
+
<% unless with_cookie_authentication? %> <div id="products"><br>Loading...</div><% else %>
|
51
51
|
<ul>
|
52
52
|
<%% @products.each do |product| %>
|
53
53
|
<li><%%= link_to product.title, "https://#{@current_shopify_session.domain}/admin/products/#{product.id}", target: "_top" %></li>
|
@@ -55,17 +55,17 @@
|
|
55
55
|
</ul>
|
56
56
|
|
57
57
|
<hr>
|
58
|
-
|
58
|
+
<% end %>
|
59
59
|
<h2>Webhooks</h2>
|
60
60
|
|
61
61
|
<%% if @webhooks.present? %>
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
62
|
+
<ul>
|
63
|
+
<%% @webhooks.each do |webhook| %>
|
64
|
+
<li><%%= webhook.topic %> : <%%= webhook.address %></li>
|
65
|
+
<%% end %>
|
66
|
+
</ul>
|
67
67
|
<%% else %>
|
68
|
-
|
69
|
-
<%% end
|
68
|
+
<p>This app has not created any webhooks for this Shop. Add webhooks to your ShopifyApp initializer if you need webhooks</p>
|
69
|
+
<%% end %>
|
70
70
|
</body>
|
71
71
|
</html>
|
@@ -11,6 +11,7 @@ module ShopifyApp
|
|
11
11
|
class_option :scope, type: :array, default: ['read_products']
|
12
12
|
class_option :embedded, type: :string, default: 'true'
|
13
13
|
class_option :api_version, type: :string, default: nil
|
14
|
+
class_option :with_cookie_authentication, type: :boolean, default: false
|
14
15
|
|
15
16
|
def create_shopify_app_initializer
|
16
17
|
@application_name = format_array_argument(options['application_name'])
|
@@ -78,6 +79,10 @@ module ShopifyApp
|
|
78
79
|
def format_array_argument(array)
|
79
80
|
array.join(' ').tr('"', '')
|
80
81
|
end
|
82
|
+
|
83
|
+
def with_cookie_authentication?
|
84
|
+
options['with_cookie_authentication'] || !embedded_app?
|
85
|
+
end
|
81
86
|
end
|
82
87
|
end
|
83
88
|
end
|
@@ -9,7 +9,8 @@ ShopifyApp.configure do |config|
|
|
9
9
|
config.after_authenticate_job = false
|
10
10
|
config.api_version = "<%= @api_version %>"
|
11
11
|
config.shop_session_repository = 'Shop'
|
12
|
-
config.allow_jwt_authentication =
|
12
|
+
config.allow_jwt_authentication = <%= !with_cookie_authentication? %>
|
13
|
+
config.allow_cookie_authentication = <%= with_cookie_authentication? %>
|
13
14
|
end
|
14
15
|
|
15
16
|
# ShopifyApp::Utils.fetch_known_api_versions # Uncomment to fetch known api versions from shopify servers on boot
|
@@ -39,12 +39,15 @@ module ShopifyApp
|
|
39
39
|
# allow enabling jwt headers for authentication
|
40
40
|
attr_accessor :allow_jwt_authentication
|
41
41
|
|
42
|
+
attr_accessor :allow_cookie_authentication
|
43
|
+
|
42
44
|
def initialize
|
43
45
|
@root_url = '/'
|
44
46
|
@myshopify_domain = 'myshopify.com'
|
45
47
|
@scripttags_manager_queue_name = Rails.application.config.active_job.queue_name
|
46
48
|
@webhooks_manager_queue_name = Rails.application.config.active_job.queue_name
|
47
49
|
@disable_webpacker = ENV['SHOPIFY_APP_DISABLE_WEBPACKER'].present?
|
50
|
+
@allow_cookie_authentication = true
|
48
51
|
end
|
49
52
|
|
50
53
|
def login_url
|
@@ -57,6 +57,7 @@ module ShopifyApp
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def user_session_by_cookie
|
60
|
+
return unless ShopifyApp.configuration.allow_cookie_authentication
|
60
61
|
return unless session[:user_id].present?
|
61
62
|
ShopifyApp::SessionRepository.retrieve_user_session(session[:user_id])
|
62
63
|
end
|
@@ -72,6 +73,7 @@ module ShopifyApp
|
|
72
73
|
end
|
73
74
|
|
74
75
|
def shop_session_by_cookie
|
76
|
+
return unless ShopifyApp.configuration.allow_cookie_authentication
|
75
77
|
return unless session[:shop_id].present?
|
76
78
|
ShopifyApp::SessionRepository.retrieve_shop_session(session[:shop_id])
|
77
79
|
end
|
data/lib/shopify_app/version.rb
CHANGED
data/package.json
CHANGED
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: 16.
|
4
|
+
version: 16.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: browser_sniffer
|
@@ -269,6 +269,7 @@ files:
|
|
269
269
|
- app/assets/javascripts/shopify_app/top_level.js
|
270
270
|
- app/assets/javascripts/shopify_app/top_level_interaction.js
|
271
271
|
- app/controllers/concerns/shopify_app/authenticated.rb
|
272
|
+
- app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
|
272
273
|
- app/controllers/concerns/shopify_app/require_known_shop.rb
|
273
274
|
- app/controllers/shopify_app/authenticated_controller.rb
|
274
275
|
- app/controllers/shopify_app/callback_controller.rb
|