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

Localhost by default - remove https:// assumption throughout codebase #1518

Merged
merged 11 commits into from
Oct 14, 2022

Conversation

nelsonwittwer
Copy link
Contributor

@nelsonwittwer nelsonwittwer commented Sep 23, 2022

What this PR does

This PR will work in tandem with this PR in the ruby API. This will enable users to run shopify_app withlocalhost instead of mandating a tunnel for OAuth redirects.

This removes hard coded https:// and uses the ShopifyAPI::Context.host and or ShopifyAPI::Context.host_scheme to build redirect links.

Reviewer's guide to testing

Ensure any modified links still work as expected.

Checklist

Before submitting the PR, please consider if any of the following are needed:

  • Update CHANGELOG.md if the changes would impact users
  • Update README.md, if appropriate.
  • Update any relevant pages in /docs, if necessary
  • For security fixes, the Disclosure Policy must be followed.

@nelsonwittwer nelsonwittwer changed the title use ShopifyAPI::Context.host instead of assume https:// WIP - use ShopifyAPI::Context.host instead of assume https:// Sep 23, 2022
@nelsonwittwer nelsonwittwer changed the title WIP - use ShopifyAPI::Context.host instead of assume https:// use ShopifyAPI::Context.host instead of assume https:// Oct 12, 2022
@nelsonwittwer nelsonwittwer changed the title use ShopifyAPI::Context.host instead of assume https:// Add support for localhost Oct 12, 2022
@nelsonwittwer nelsonwittwer changed the title Add support for localhost Localhost by default - remove https:// assumption throughout codebase Oct 12, 2022
Copy link
Contributor

@paulomarg paulomarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a few of these could stay as https (anything that points to a Shopify address and not host_name).

It'll still work because I'm pretty sure Shopify will go http => https, but we can reduce the number of redirects by going straight to https when hitting Shopify.

app/views/shopify_app/sessions/enable_cookies.html.erb Outdated Show resolved Hide resolved
@@ -18,7 +18,7 @@

<%= javascript_include_tag('shopify_app/top_level', crossorigin: 'anonymous', integrity: true) %>
</head>
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="https://<%= @shop %>" data-host="<%= @host %>" data-redirect-url="<%= @url %>">
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="<%= ShopifyAPI::Context.host_scheme + "://" + @shop %>" data-host="<%= @host %>" data-redirect-url="<%= @url %>">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could have a method like ShopifyAPI::Context.uri_for_shop(shop) to avoid awkward string manipulation in the view.

@@ -13,7 +13,7 @@
id: 'redirection-target',
data: {
target: {
myshopifyUrl: "https://#{current_shopify_domain}",
myshopifyUrl: ShopifyAPI::Context.host_scheme + "://" + current_shopify_domain,
Copy link
Contributor

@andyw8 andyw8 Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have a method like current_shopify_url?

@nelsonwittwer nelsonwittwer merged commit 30f14ff into main Oct 14, 2022
@nelsonwittwer nelsonwittwer deleted the nelsonwittwer/localhost branch October 14, 2022 15:43
@@ -38,7 +38,7 @@ Rails.application.config.after_initialize do
api_key: ShopifyApp.configuration.api_key,
api_secret_key: ShopifyApp.configuration.secret,
api_version: ShopifyApp.configuration.api_version,
host_name: URI(ENV.fetch('HOST', '')).host || '',
host: ENV['HOST'],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either this or Shopify/shopify-api-ruby#1017 is incorrect. host_name is still required by the setup function. I'm not sure if it should still be required or should be optional now. If it should be optional maybe there should be some error checking to ensure that host and host_name don't conflict?

fabriazza pushed a commit to fabriazza/shopify_app that referenced this pull request Feb 1, 2023
…se (Shopify#1518)

* use ShopifyAPI::Context.host instead of assume https://

* use host scheme correctly

* use ShopifyAPI::Context.host instead of composition

* restore domain_host pattern

* always tls with current_shopify_domain

* typo + revert to tls default with cookies

* 12.0 shopify_api dependency

* update 12.1.0 API

* rubocop updates

* docs, readme, and changelog for localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants