Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EnsureAuthenticatedLinks compatible with AppBridge 2 #1277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,22 @@ module EnsureAuthenticatedLinks

private

def splash_page
splash_page_with_params(
return_to: request.fullpath,
shop: current_shopify_domain,
host: params[:host]
)
end

def splash_page_with_params(params)
uri = URI(root_path)
uri.query = params.compact.to_query
uri.to_s
end

def redirect_to_splash_page
splash_page_path = root_path(return_to: request.fullpath, shop: current_shopify_domain)
redirect_to(splash_page_path)
redirect_to(splash_page)
rescue ShopifyApp::LoginProtection::ShopifyDomainNotFound => error
Rails.logger.warn("[ShopifyApp::EnsureAuthenticatedLinks] Redirecting to login: [#{error.class}] "\
"Could not determine current shop domain")
Expand Down
8 changes: 8 additions & 0 deletions test/controllers/concerns/ensure_authenticated_links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def current_shopify_domain
assert_redirected_to expected_path
end

test 'redirects to splash page with a return_to, shop and host params if no session token is present' do
get :some_link, params: { shop: @shop_domain, host: 'test-host' }

expected_path = "/?host=test-host&return_to=#{CGI.escape(request.fullpath)}&shop=#{@shop_domain}"

assert_redirected_to expected_path
end

test 'returns the requested resource if a valid session token exists' do
request.env['jwt.shopify_domain'] = @shop_domain

Expand Down