shopify_app 18.1.1 → 20.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +3 -3
- data/.gitignore +1 -0
- data/CHANGELOG.md +39 -3
- data/Gemfile +3 -2
- data/Gemfile.lock +128 -162
- data/README.md +0 -1
- data/Rakefile +4 -3
- data/app/assets/javascripts/shopify_app/app_bridge_3.1.1.js +10 -0
- data/app/assets/javascripts/shopify_app/app_bridge_redirect.js +2 -3
- data/app/assets/javascripts/shopify_app/app_bridge_utils_3.1.1.js +1 -0
- data/app/assets/javascripts/shopify_app/redirect.js +6 -8
- data/app/controllers/concerns/shopify_app/authenticated.rb +3 -0
- data/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb +1 -1
- data/app/controllers/concerns/shopify_app/require_known_shop.rb +1 -0
- data/app/controllers/concerns/shopify_app/shop_access_scopes_verification.rb +1 -1
- data/app/controllers/shopify_app/authenticated_controller.rb +1 -0
- data/app/controllers/shopify_app/callback_controller.rb +49 -134
- data/app/controllers/shopify_app/sessions_controller.rb +26 -131
- data/app/controllers/shopify_app/webhooks_controller.rb +5 -23
- data/app/views/shopify_app/sessions/enable_cookies.html.erb +1 -1
- data/app/views/shopify_app/sessions/request_storage_access.html.erb +1 -1
- data/app/views/shopify_app/sessions/top_level_interaction.html.erb +1 -1
- data/app/views/shopify_app/shared/redirect.html.erb +1 -1
- data/config/routes.rb +20 -12
- data/docs/Releasing.md +1 -1
- data/docs/Troubleshooting.md +0 -3
- data/docs/Upgrading.md +116 -14
- data/docs/shopify_app/webhooks.md +1 -1
- data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +10 -9
- data/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb +1 -0
- data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +4 -3
- data/lib/generators/shopify_app/add_webhook/add_webhook_generator.rb +13 -12
- data/lib/generators/shopify_app/add_webhook/templates/webhook_job.rb.tt +9 -1
- data/lib/generators/shopify_app/app_proxy_controller/app_proxy_controller_generator.rb +7 -6
- data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_controller.rb +2 -1
- data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_route.rb +1 -1
- data/lib/generators/shopify_app/authenticated_controller/authenticated_controller_generator.rb +3 -3
- data/lib/generators/shopify_app/controllers/controllers_generator.rb +4 -3
- data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +11 -15
- data/lib/generators/shopify_app/home_controller/templates/home_controller.rb +2 -2
- data/lib/generators/shopify_app/home_controller/templates/index.html.erb +3 -3
- data/lib/generators/shopify_app/install/install_generator.rb +25 -74
- data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +1 -1
- data/lib/generators/shopify_app/install/templates/session_store.rb +2 -1
- data/lib/generators/shopify_app/install/templates/shopify_app.rb.tt +33 -5
- data/lib/generators/shopify_app/products_controller/products_controller_generator.rb +3 -3
- data/lib/generators/shopify_app/products_controller/templates/products_controller.rb +1 -1
- data/lib/generators/shopify_app/rotate_shopify_token_job/rotate_shopify_token_job_generator.rb +4 -4
- data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token.rake +1 -0
- data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token_job.rb +1 -1
- data/lib/generators/shopify_app/routes/routes_generator.rb +6 -5
- data/lib/generators/shopify_app/routes/templates/routes.rb +5 -5
- data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +11 -10
- data/lib/generators/shopify_app/shop_model/templates/shop.rb +1 -0
- data/lib/generators/shopify_app/shopify_app_generator.rb +4 -3
- data/lib/generators/shopify_app/user_model/templates/user.rb +1 -0
- data/lib/generators/shopify_app/user_model/user_model_generator.rb +11 -10
- data/lib/generators/shopify_app/views/views_generator.rb +4 -3
- data/lib/shopify_app/access_scopes/shop_strategy.rb +2 -2
- data/lib/shopify_app/access_scopes/user_strategy.rb +4 -4
- data/lib/shopify_app/configuration.rb +33 -14
- data/lib/shopify_app/controller_concerns/app_proxy_verification.rb +4 -3
- data/lib/shopify_app/controller_concerns/csrf_protection.rb +2 -1
- data/lib/shopify_app/controller_concerns/embedded_app.rb +4 -3
- data/lib/shopify_app/controller_concerns/ensure_billing.rb +254 -0
- data/lib/shopify_app/controller_concerns/itp.rb +3 -3
- data/lib/shopify_app/controller_concerns/localization.rb +1 -0
- data/lib/shopify_app/controller_concerns/login_protection.rb +81 -73
- data/lib/shopify_app/controller_concerns/payload_verification.rb +3 -2
- data/lib/shopify_app/controller_concerns/webhook_verification.rb +2 -1
- data/lib/shopify_app/engine.rb +7 -15
- data/lib/shopify_app/jobs/scripttags_manager_job.rb +2 -2
- data/lib/shopify_app/jobs/webhooks_manager_job.rb +4 -5
- data/lib/shopify_app/managers/scripttags_manager.rb +11 -4
- data/lib/shopify_app/managers/webhooks_manager.rb +42 -44
- data/lib/shopify_app/middleware/jwt_middleware.rb +5 -4
- data/lib/shopify_app/session/in_memory_session_store.rb +1 -0
- data/lib/shopify_app/session/in_memory_shop_session_store.rb +2 -1
- data/lib/shopify_app/session/in_memory_user_session_store.rb +1 -0
- data/lib/shopify_app/session/jwt.rb +9 -8
- data/lib/shopify_app/session/null_user_session_store.rb +2 -1
- data/lib/shopify_app/session/session_repository.rb +37 -0
- data/lib/shopify_app/session/session_storage.rb +4 -6
- data/lib/shopify_app/session/shop_session_storage.rb +6 -6
- data/lib/shopify_app/session/shop_session_storage_with_scopes.rb +7 -8
- data/lib/shopify_app/session/user_session_storage.rb +19 -6
- data/lib/shopify_app/session/user_session_storage_with_scopes.rb +22 -9
- data/lib/shopify_app/test_helpers/all.rb +2 -1
- data/lib/shopify_app/test_helpers/webhook_verification_helper.rb +4 -3
- data/lib/shopify_app/utils.rb +4 -10
- data/lib/shopify_app/version.rb +2 -1
- data/lib/shopify_app.rb +36 -40
- data/package.json +1 -1
- data/shopify_app.gemspec +22 -21
- data/yarn.lock +9 -9
- metadata +50 -53
- data/app/assets/javascripts/shopify_app/app_bridge_1.30.0.js +0 -1
- data/lib/generators/shopify_app/install/templates/omniauth.rb +0 -4
- data/lib/generators/shopify_app/install/templates/shopify_provider.rb.tt +0 -8
- data/lib/generators/shopify_app/install/templates/user_agent.rb +0 -6
- data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +0 -34
- data/lib/shopify_app/omniauth/omniauth_configuration.rb +0 -64
@@ -4,180 +4,95 @@ module ShopifyApp
|
|
4
4
|
# Performs login after OAuth completes
|
5
5
|
class CallbackController < ActionController::Base
|
6
6
|
include ShopifyApp::LoginProtection
|
7
|
+
include ShopifyApp::EnsureBilling
|
7
8
|
|
8
9
|
def callback
|
9
|
-
|
10
|
+
begin
|
11
|
+
filtered_params = request.parameters.symbolize_keys.slice(:code, :shop, :timestamp, :state, :host, :hmac)
|
12
|
+
|
13
|
+
auth_result = ShopifyAPI::Auth::Oauth.validate_auth_callback(
|
14
|
+
cookies: {
|
15
|
+
ShopifyAPI::Auth::Oauth::SessionCookie::SESSION_COOKIE_NAME =>
|
16
|
+
cookies.encrypted[ShopifyAPI::Auth::Oauth::SessionCookie::SESSION_COOKIE_NAME],
|
17
|
+
},
|
18
|
+
auth_query: ShopifyAPI::Auth::Oauth::AuthQuery.new(**filtered_params)
|
19
|
+
)
|
20
|
+
rescue
|
21
|
+
return respond_with_error
|
22
|
+
end
|
23
|
+
|
24
|
+
cookies.encrypted[auth_result[:cookie].name] = {
|
25
|
+
expires: auth_result[:cookie].expires,
|
26
|
+
secure: true,
|
27
|
+
http_only: true,
|
28
|
+
value: auth_result[:cookie].value,
|
29
|
+
}
|
10
30
|
|
11
|
-
|
31
|
+
session[:shopify_user_id] = auth_result[:session].associated_user.id if auth_result[:session].online?
|
12
32
|
|
13
|
-
if start_user_token_flow?
|
33
|
+
if start_user_token_flow?(auth_result[:session])
|
14
34
|
return respond_with_user_token_flow
|
15
35
|
end
|
16
36
|
|
17
|
-
perform_post_authenticate_jobs
|
37
|
+
perform_post_authenticate_jobs(auth_result[:session])
|
38
|
+
has_payment = check_billing(auth_result[:session])
|
18
39
|
|
19
|
-
respond_successfully
|
40
|
+
respond_successfully if has_payment
|
20
41
|
end
|
21
42
|
|
22
43
|
private
|
23
44
|
|
24
45
|
def respond_successfully
|
25
|
-
|
26
|
-
head(:ok)
|
27
|
-
else
|
28
|
-
redirect_to(return_address)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def respond_with_user_token_flow
|
33
|
-
redirect_to(login_url_with_optional_shop)
|
34
|
-
end
|
35
|
-
|
36
|
-
def store_access_token_and_build_session
|
37
|
-
if native_browser_request?
|
38
|
-
reset_session_options
|
39
|
-
end
|
40
|
-
set_shopify_session
|
41
|
-
end
|
42
|
-
|
43
|
-
def invalid_request?
|
44
|
-
return true unless auth_hash
|
45
|
-
|
46
|
-
jwt_request? && !valid_jwt_auth?
|
47
|
-
end
|
48
|
-
|
49
|
-
def native_browser_request?
|
50
|
-
!jwt_request?
|
51
|
-
end
|
52
|
-
|
53
|
-
def perform_post_authenticate_jobs
|
54
|
-
install_webhooks
|
55
|
-
install_scripttags
|
56
|
-
perform_after_authenticate_job
|
46
|
+
redirect_to(return_address)
|
57
47
|
end
|
58
48
|
|
59
49
|
def respond_with_error
|
60
|
-
|
61
|
-
|
62
|
-
else
|
63
|
-
flash[:error] = I18n.t('could_not_log_in')
|
64
|
-
redirect_to(login_url_with_optional_shop)
|
65
|
-
end
|
50
|
+
flash[:error] = I18n.t("could_not_log_in")
|
51
|
+
redirect_to(login_url_with_optional_shop)
|
66
52
|
end
|
67
53
|
|
68
|
-
|
69
|
-
|
70
|
-
def user_session_by_cookie
|
71
|
-
return unless session[:user_id].present?
|
72
|
-
ShopifyApp::SessionRepository.retrieve_user_session(session[:user_id])
|
54
|
+
def respond_with_user_token_flow
|
55
|
+
redirect_to(login_url_with_optional_shop)
|
73
56
|
end
|
74
57
|
|
75
|
-
def start_user_token_flow?
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
return false unless ShopifyApp::SessionRepository.user_storage.present?
|
80
|
-
update_user_access_scopes?
|
81
|
-
end
|
58
|
+
def start_user_token_flow?(shopify_session)
|
59
|
+
return false unless ShopifyApp::SessionRepository.user_storage.present?
|
60
|
+
return false if shopify_session.online?
|
61
|
+
update_user_access_scopes?
|
82
62
|
end
|
83
63
|
|
84
64
|
def update_user_access_scopes?
|
85
|
-
return true if
|
86
|
-
user_access_scopes_strategy.update_access_scopes?(
|
65
|
+
return true if session[:shopify_user_id].nil?
|
66
|
+
user_access_scopes_strategy.update_access_scopes?(shopify_user_id: session[:shopify_user_id])
|
87
67
|
end
|
88
68
|
|
89
69
|
def user_access_scopes_strategy
|
90
70
|
ShopifyApp.configuration.user_access_scopes_strategy
|
91
71
|
end
|
92
72
|
|
93
|
-
def
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
def valid_jwt_auth?
|
98
|
-
auth_hash && jwt_shopify_domain == shop_name && jwt_shopify_user_id == associated_user_id
|
73
|
+
def perform_post_authenticate_jobs(session)
|
74
|
+
install_webhooks(session)
|
75
|
+
install_scripttags(session)
|
76
|
+
perform_after_authenticate_job(session)
|
99
77
|
end
|
100
78
|
|
101
|
-
def
|
102
|
-
request.env['omniauth.auth']
|
103
|
-
end
|
104
|
-
|
105
|
-
def shop_name
|
106
|
-
auth_hash.uid
|
107
|
-
end
|
108
|
-
|
109
|
-
def offline_access_token
|
110
|
-
ShopifyApp::SessionRepository.retrieve_shop_session_by_shopify_domain(shop_name)&.token
|
111
|
-
end
|
112
|
-
|
113
|
-
def online_access_token
|
114
|
-
ShopifyApp::SessionRepository.retrieve_user_session_by_shopify_user_id(associated_user_id)&.token
|
115
|
-
end
|
116
|
-
|
117
|
-
def associated_user
|
118
|
-
return unless auth_hash.dig('extra', 'associated_user').present?
|
119
|
-
|
120
|
-
auth_hash['extra']['associated_user'].merge('scope' => auth_hash['extra']['associated_user_scope'])
|
121
|
-
end
|
122
|
-
|
123
|
-
def associated_user_id
|
124
|
-
associated_user && associated_user['id']
|
125
|
-
end
|
126
|
-
|
127
|
-
def token
|
128
|
-
auth_hash['credentials']['token']
|
129
|
-
end
|
130
|
-
|
131
|
-
def access_scopes
|
132
|
-
auth_hash.dig('extra', 'scope')
|
133
|
-
end
|
134
|
-
|
135
|
-
def reset_session_options
|
136
|
-
request.session_options[:renew] = true
|
137
|
-
session.delete(:_csrf_token)
|
138
|
-
end
|
139
|
-
|
140
|
-
def set_shopify_session
|
141
|
-
session_store = ShopifyAPI::Session.new(
|
142
|
-
domain: shop_name,
|
143
|
-
token: token,
|
144
|
-
api_version: ShopifyApp.configuration.api_version,
|
145
|
-
access_scopes: access_scopes
|
146
|
-
)
|
147
|
-
|
148
|
-
session[:shopify_user] = associated_user
|
149
|
-
if session[:shopify_user].present?
|
150
|
-
session[:shop_id] = nil if shop_session && shop_session.domain != shop_name
|
151
|
-
session[:user_id] = ShopifyApp::SessionRepository.store_user_session(session_store, associated_user)
|
152
|
-
else
|
153
|
-
session[:shop_id] = ShopifyApp::SessionRepository.store_shop_session(session_store)
|
154
|
-
session[:user_id] = nil if user_session && user_session.domain != shop_name
|
155
|
-
end
|
156
|
-
session[:shopify_domain] = shop_name
|
157
|
-
session[:user_session] = auth_hash&.extra&.session
|
158
|
-
end
|
159
|
-
|
160
|
-
def install_webhooks
|
79
|
+
def install_webhooks(session)
|
161
80
|
return unless ShopifyApp.configuration.has_webhooks?
|
162
81
|
|
163
|
-
WebhooksManager.queue(
|
164
|
-
shop_name,
|
165
|
-
offline_access_token || online_access_token,
|
166
|
-
ShopifyApp.configuration.webhooks
|
167
|
-
)
|
82
|
+
WebhooksManager.queue(session.shop, session.access_token)
|
168
83
|
end
|
169
84
|
|
170
|
-
def install_scripttags
|
85
|
+
def install_scripttags(session)
|
171
86
|
return unless ShopifyApp.configuration.has_scripttags?
|
172
87
|
|
173
88
|
ScripttagsManager.queue(
|
174
|
-
|
175
|
-
|
89
|
+
session.shop,
|
90
|
+
session.access_token,
|
176
91
|
ShopifyApp.configuration.scripttags
|
177
92
|
)
|
178
93
|
end
|
179
94
|
|
180
|
-
def perform_after_authenticate_job
|
95
|
+
def perform_after_authenticate_job(session)
|
181
96
|
config = ShopifyApp.configuration.after_authenticate_job
|
182
97
|
|
183
98
|
return unless config && config[:job].present?
|
@@ -186,9 +101,9 @@ module ShopifyApp
|
|
186
101
|
job = job.constantize if job.is_a?(String)
|
187
102
|
|
188
103
|
if config[:inline] == true
|
189
|
-
job.perform_now(shop_domain: session
|
104
|
+
job.perform_now(shop_domain: session.shop)
|
190
105
|
else
|
191
|
-
job.perform_later(shop_domain: session
|
106
|
+
job.perform_later(shop_domain: session.shop)
|
192
107
|
end
|
193
108
|
end
|
194
109
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module ShopifyApp
|
3
4
|
class SessionsController < ActionController::Base
|
4
5
|
include ShopifyApp::LoginProtection
|
@@ -6,7 +7,7 @@ module ShopifyApp
|
|
6
7
|
layout false, only: :new
|
7
8
|
|
8
9
|
after_action only: [:new, :create] do |controller|
|
9
|
-
controller.response.headers.except!(
|
10
|
+
controller.response.headers.except!("X-Frame-Options")
|
10
11
|
end
|
11
12
|
|
12
13
|
def new
|
@@ -17,41 +18,14 @@ module ShopifyApp
|
|
17
18
|
authenticate
|
18
19
|
end
|
19
20
|
|
20
|
-
def enable_cookies
|
21
|
-
return unless validate_shop_presence
|
22
|
-
|
23
|
-
render(:enable_cookies, layout: false, locals: {
|
24
|
-
does_not_have_storage_access_url: top_level_interaction_path(
|
25
|
-
shop: sanitized_shop_name,
|
26
|
-
return_to: params[:return_to]
|
27
|
-
),
|
28
|
-
has_storage_access_url: login_url_with_optional_shop(top_level: true),
|
29
|
-
app_target_url: granted_storage_access_path(
|
30
|
-
shop: sanitized_shop_name,
|
31
|
-
return_to: params[:return_to]
|
32
|
-
),
|
33
|
-
current_shopify_domain: current_shopify_domain,
|
34
|
-
})
|
35
|
-
end
|
36
|
-
|
37
21
|
def top_level_interaction
|
38
22
|
@url = login_url_with_optional_shop(top_level: true)
|
39
23
|
validate_shop_presence
|
40
24
|
end
|
41
25
|
|
42
|
-
def granted_storage_access
|
43
|
-
return unless validate_shop_presence
|
44
|
-
|
45
|
-
session['shopify.granted_storage_access'] = true
|
46
|
-
|
47
|
-
copy_return_to_param_to_session
|
48
|
-
|
49
|
-
redirect_to(return_address_with_params({ shop: @shop }))
|
50
|
-
end
|
51
|
-
|
52
26
|
def destroy
|
53
27
|
reset_session
|
54
|
-
flash[:notice] = I18n.t(
|
28
|
+
flash[:notice] = I18n.t(".logged_out")
|
55
29
|
redirect_to(login_url_with_optional_shop)
|
56
30
|
end
|
57
31
|
|
@@ -59,69 +33,33 @@ module ShopifyApp
|
|
59
33
|
|
60
34
|
def authenticate
|
61
35
|
return render_invalid_shop_error unless sanitized_shop_name.present?
|
62
|
-
session['shopify.omniauth_params'] = { shop: sanitized_shop_name }
|
63
36
|
|
64
37
|
copy_return_to_param_to_session
|
65
38
|
|
66
|
-
|
67
|
-
|
68
|
-
if user_agent_can_partition_cookies
|
69
|
-
authenticate_with_partitioning
|
39
|
+
if top_level?
|
40
|
+
start_oauth
|
70
41
|
else
|
71
|
-
|
42
|
+
redirect_auth_to_top_level
|
72
43
|
end
|
73
44
|
end
|
74
45
|
|
75
|
-
def
|
76
|
-
|
77
|
-
redirect_to_request_storage_access
|
78
|
-
elsif authenticate_in_context?
|
79
|
-
authenticate_in_context
|
80
|
-
else
|
81
|
-
authenticate_at_top_level
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def authenticate_with_partitioning
|
86
|
-
if session['shopify.cookies_persist']
|
87
|
-
clear_top_level_oauth_cookie
|
88
|
-
authenticate_in_context
|
89
|
-
else
|
90
|
-
set_top_level_oauth_cookie
|
91
|
-
enable_cookie_access
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
# Override shop_session_by_cookie from LoginProtection to bypass allow_cookie_authentication
|
96
|
-
# setting check because session cookies are justified at top level
|
97
|
-
def shop_session_by_cookie
|
98
|
-
return unless session[:shop_id].present?
|
99
|
-
ShopifyApp::SessionRepository.retrieve_shop_session(session[:shop_id])
|
100
|
-
end
|
101
|
-
|
102
|
-
# rubocop:disable Lint/SuppressedException
|
103
|
-
def set_user_tokens_option
|
104
|
-
current_shop_session = shop_session
|
46
|
+
def start_oauth
|
47
|
+
callback_url = ShopifyApp.configuration.login_callback_url.gsub(%r{^/}, "")
|
105
48
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
49
|
+
auth_attributes = ShopifyAPI::Auth::Oauth.begin_auth(
|
50
|
+
shop: sanitized_shop_name,
|
51
|
+
redirect_path: "/#{callback_url}",
|
52
|
+
is_online: user_session_expected?
|
53
|
+
)
|
54
|
+
cookies.encrypted[auth_attributes[:cookie].name] = {
|
55
|
+
expires: auth_attributes[:cookie].expires,
|
56
|
+
secure: true,
|
57
|
+
http_only: true,
|
58
|
+
value: auth_attributes[:cookie].value,
|
59
|
+
}
|
112
60
|
|
113
|
-
|
114
|
-
domain: current_shop_session.domain,
|
115
|
-
token: current_shop_session.token,
|
116
|
-
api_version: current_shop_session.api_version
|
117
|
-
) do
|
118
|
-
ShopifyAPI::Metafield.find(:token_validity_bogus_check)
|
119
|
-
end
|
120
|
-
rescue ActiveResource::UnauthorizedAccess
|
121
|
-
session[:user_tokens] = false
|
122
|
-
rescue StandardError
|
61
|
+
redirect_to(auth_attributes[:auth_route], allow_other_host: true)
|
123
62
|
end
|
124
|
-
# rubocop:enable Lint/SuppressedException
|
125
63
|
|
126
64
|
def validate_shop_presence
|
127
65
|
@shop = sanitized_shop_name
|
@@ -134,64 +72,21 @@ module ShopifyApp
|
|
134
72
|
end
|
135
73
|
|
136
74
|
def copy_return_to_param_to_session
|
137
|
-
session[:return_to] = RedirectSafely.make_safe(params[:return_to],
|
75
|
+
session[:return_to] = RedirectSafely.make_safe(params[:return_to], "/") if params[:return_to]
|
138
76
|
end
|
139
77
|
|
140
78
|
def render_invalid_shop_error
|
141
|
-
flash[:error] = I18n.t(
|
79
|
+
flash[:error] = I18n.t("invalid_shop_url")
|
142
80
|
redirect_to(return_address)
|
143
81
|
end
|
144
82
|
|
145
|
-
def
|
146
|
-
fullpage_redirect_to(enable_cookies_path(
|
147
|
-
shop: sanitized_shop_name,
|
148
|
-
return_to: session[:return_to]
|
149
|
-
))
|
150
|
-
end
|
151
|
-
|
152
|
-
def authenticate_in_context
|
153
|
-
post_redirect_to_auth_shopify
|
154
|
-
end
|
155
|
-
|
156
|
-
def post_redirect_to_auth_shopify
|
157
|
-
render('shopify_app/shared/post_redirect_to_auth_shopify', layout: false)
|
158
|
-
end
|
159
|
-
|
160
|
-
def authenticate_at_top_level
|
161
|
-
fullpage_redirect_to(login_url_with_optional_shop(top_level: true))
|
162
|
-
end
|
163
|
-
|
164
|
-
def authenticate_in_context?
|
83
|
+
def top_level?
|
165
84
|
return true unless ShopifyApp.configuration.embedded_app?
|
166
|
-
params[:top_level]
|
85
|
+
!params[:top_level].nil?
|
167
86
|
end
|
168
87
|
|
169
|
-
def
|
170
|
-
|
171
|
-
return false if params[:top_level]
|
172
|
-
return false if user_agent_is_mobile
|
173
|
-
return false if user_agent_is_pos
|
174
|
-
|
175
|
-
!session['shopify.granted_storage_access']
|
176
|
-
end
|
177
|
-
|
178
|
-
def redirect_to_request_storage_access
|
179
|
-
render(
|
180
|
-
:request_storage_access,
|
181
|
-
layout: false,
|
182
|
-
locals: {
|
183
|
-
does_not_have_storage_access_url: top_level_interaction_path(
|
184
|
-
shop: sanitized_shop_name,
|
185
|
-
return_to: session[:return_to]
|
186
|
-
),
|
187
|
-
has_storage_access_url: login_url_with_optional_shop(top_level: true),
|
188
|
-
app_target_url: granted_storage_access_path(
|
189
|
-
shop: sanitized_shop_name,
|
190
|
-
return_to: session[:return_to]
|
191
|
-
),
|
192
|
-
current_shopify_domain: current_shopify_domain,
|
193
|
-
}
|
194
|
-
)
|
88
|
+
def redirect_auth_to_top_level
|
89
|
+
fullpage_redirect_to(login_url_with_optional_shop(top_level: true))
|
195
90
|
end
|
196
91
|
end
|
197
92
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module ShopifyApp
|
3
4
|
class MissingWebhookJobError < StandardError; end
|
4
5
|
|
@@ -7,30 +8,11 @@ module ShopifyApp
|
|
7
8
|
|
8
9
|
def receive
|
9
10
|
params.permit!
|
10
|
-
webhook_job_klass.perform_later(shop_domain: shop_domain, webhook: webhook_params.to_h)
|
11
|
-
head(:ok)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def webhook_job_klass
|
21
|
-
webhook_job_klass_name.safe_constantize || raise(ShopifyApp::MissingWebhookJobError)
|
22
|
-
end
|
23
|
-
|
24
|
-
def webhook_job_klass_name(type = webhook_type)
|
25
|
-
[webhook_namespace, "#{type}_job"].compact.join('/').classify
|
26
|
-
end
|
27
|
-
|
28
|
-
def webhook_type
|
29
|
-
params[:type]
|
30
|
-
end
|
31
|
-
|
32
|
-
def webhook_namespace
|
33
|
-
ShopifyApp.configuration.webhook_jobs_namespace
|
12
|
+
ShopifyAPI::Webhooks::Registry.process(
|
13
|
+
ShopifyAPI::Webhooks::Request.new(raw_body: request.raw_post, headers: request.headers.to_h)
|
14
|
+
)
|
15
|
+
head(:ok)
|
34
16
|
end
|
35
17
|
end
|
36
18
|
end
|
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
<%= javascript_include_tag('shopify_app/enable_cookies', crossorigin: 'anonymous', integrity: true) %>
|
19
19
|
</head>
|
20
|
-
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="<%= @shop %>" data-redirect-url="<%= @url %>" data-
|
20
|
+
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="<%= @shop %>" data-redirect-url="<%= @url %>" data-host="<%= params[:host] %>" data-return-to="<%= params[:return_to] %>">
|
21
21
|
<%=
|
22
22
|
content_tag(
|
23
23
|
:div, nil,
|
@@ -15,7 +15,7 @@
|
|
15
15
|
}
|
16
16
|
</style>
|
17
17
|
</head>
|
18
|
-
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="<%= current_shopify_domain %>" data-return-to="<%= params[:return_to] %>">
|
18
|
+
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="<%= current_shopify_domain %>" data-host="<%= params[:host] %>" data-return-to="<%= params[:return_to] %>">
|
19
19
|
<%=
|
20
20
|
content_tag(:div, nil,
|
21
21
|
id: 'redirection-target',
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
<%= javascript_include_tag('shopify_app/top_level', crossorigin: 'anonymous', integrity: true) %>
|
20
20
|
</head>
|
21
|
-
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="https://<%= @shop %>" data-redirect-url="<%= @url %>">
|
21
|
+
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="https://<%= @shop %>" data-host="<%= @host %>" data-redirect-url="<%= @url %>">
|
22
22
|
<main id="TopLevelInteractionContent">
|
23
23
|
<div class="Polaris-Page">
|
24
24
|
<div class="Polaris-Page__Content">
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<title>Redirecting…</title>
|
8
8
|
<%= javascript_include_tag('shopify_app/redirect', crossorigin: 'anonymous', integrity: true) %>
|
9
9
|
</head>
|
10
|
-
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="<%= current_shopify_domain %>">
|
10
|
+
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="<%= current_shopify_domain %>" data-host="<%= params[:host] %>" >
|
11
11
|
<%=
|
12
12
|
content_tag(:div, nil,
|
13
13
|
id: 'redirection-target',
|
data/config/routes.rb
CHANGED
@@ -1,23 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
ShopifyApp::Engine.routes.draw do
|
4
|
+
login_url = ShopifyApp.configuration.login_url.gsub(/^#{ShopifyApp.configuration.root_url}/, "")
|
5
|
+
login_callback_url = ShopifyApp.configuration.login_callback_url.gsub(/^#{ShopifyApp.configuration.root_url}/, "")
|
6
|
+
|
3
7
|
controller :sessions do
|
4
|
-
get
|
5
|
-
post
|
6
|
-
get
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
:
|
12
|
-
|
13
|
-
get 'logout' => :destroy, :as => :logout
|
8
|
+
get login_url => :new, :as => :login
|
9
|
+
post login_url => :create, :as => :authenticate
|
10
|
+
get "logout" => :destroy, :as => :logout
|
11
|
+
|
12
|
+
# Kept to prevent apps relying on these routes from breaking
|
13
|
+
if login_url.gsub(%r{^/}, "") != "login"
|
14
|
+
get "login" => :new, :as => :default_login
|
15
|
+
post "login" => :create, :as => :default_authenticate
|
16
|
+
end
|
14
17
|
end
|
15
18
|
|
16
19
|
controller :callback do
|
17
|
-
get
|
20
|
+
get login_callback_url => :callback
|
21
|
+
|
22
|
+
# Kept to prevent apps relying on these routes from breaking
|
23
|
+
if login_callback_url.gsub(%r{^/}, "") != "auth/shopify/callback"
|
24
|
+
get "auth/shopify/callback" => :default_callback
|
25
|
+
end
|
18
26
|
end
|
19
27
|
|
20
28
|
namespace :webhooks do
|
21
|
-
post
|
29
|
+
post ":type" => :receive
|
22
30
|
end
|
23
31
|
end
|
data/docs/Releasing.md
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
1. Checkout and pull from master so you have the latest version of the shopify_app
|
13
13
|
1. Tag the HEAD with the version
|
14
14
|
```bash
|
15
|
-
$ git tag -f vX.Y.Z && git push
|
15
|
+
$ git tag -f vX.Y.Z && git push origin vX.Y.Z
|
16
16
|
```
|
17
17
|
1. Check that Create Release workflow successfully runs
|
18
18
|
1. Use Shipit to build and push the gem
|
data/docs/Troubleshooting.md
CHANGED
@@ -87,9 +87,6 @@ Edit `config/initializer/shopify_app.rb` and ensure the following configurations
|
|
87
87
|
```diff
|
88
88
|
+ config.embedded_app = true
|
89
89
|
|
90
|
-
+ config.allow_jwt_authentication = true
|
91
|
-
+ config.allow_cookie_authentication = false
|
92
|
-
|
93
90
|
# This line should already exist if you're using shopify_app gem 13.x.x+
|
94
91
|
+ config.shop_session_repository = 'Shop'
|
95
92
|
```
|