Skip to content

Commit

Permalink
Merge pull request #389 from Shopify/support-absolute-urls
Browse files Browse the repository at this point in the history
Allow absolute URLs in ShopifyApp::LoginProtection.redirection_javascript
  • Loading branch information
Hammadk committed Feb 27, 2017
2 parents e38a0e2 + 1d050c0 commit e435d9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/shopify_app/login_protection.rb
Expand Up @@ -79,9 +79,12 @@ def redirection_javascript(url)
// If the current window is the 'child', change the parent's URL with postMessage
} else {
normalizedLink = document.createElement('a');
normalizedLink.href = #{url.to_json};
data = JSON.stringify({
message: 'Shopify.API.remoteRedirect',
data: { location: window.location.origin + #{url.to_json} }
data: { location: normalizedLink.href }
});
window.parent.postMessage(data, "https://#{sanitized_shop_name}");
}
Expand Down
4 changes: 3 additions & 1 deletion test/controllers/sessions_controller_test.rb
Expand Up @@ -172,10 +172,12 @@ def assert_redirected_to_authentication(shop_domain, response)
target_origin = "https://#{shop_domain}".to_json

post_message_handle = "message: 'Shopify.API.remoteRedirect'"
post_message_data = "data: { location: window.location.origin + #{auth_url} }"
post_message_link = "normalizedLink.href = #{auth_url}"
post_message_data = "data: { location: normalizedLink.href }"
post_message_call = "window.parent.postMessage(data, #{target_origin});"

assert_includes response.body, post_message_handle
assert_includes response.body, post_message_link
assert_includes response.body, post_message_data
assert_includes response.body, post_message_call
end
Expand Down

0 comments on commit e435d9e

Please sign in to comment.