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

Support Unified Admin #1658

Merged
merged 1 commit into from
Mar 21, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
----------

* Support Unified Admin [#1658](https://github.com/Shopify/shopify_app/pull/1658)
* Set `access_scopes` column to string by default [#1636](https://github.com/Shopify/shopify_app/pull/1636)

21.4.1 (Feb 21, 2023)
Expand Down
12 changes: 11 additions & 1 deletion lib/shopify_app/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def sanitize_shop_domain(shop_domain)
no_shop_name_in_subdomain = uri.host == trusted_domain
from_trusted_domain = trusted_domain == uri.domain

return myshopify_domain_from_unified_admin(uri) if unified_admin?(uri) && from_trusted_domain
return nil if no_shop_name_in_subdomain || uri.host&.empty?
return uri.host if from_trusted_domain
end

nil
end

Expand Down Expand Up @@ -65,6 +65,16 @@ def uri_from_shop_domain(shop_domain)
rescue Addressable::URI::InvalidURIError
nil
end

def unified_admin?(uri)
uri.host.split(".").first == "admin"
end

def myshopify_domain_from_unified_admin(uri)
shop = uri.path.split("/").last

"#{shop}.myshopify.com"
end
end
end
end
10 changes: 10 additions & 0 deletions test/shopify_app/utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ class UtilsTest < ActiveSupport::TestCase
assert ShopifyApp::Utils.sanitize_shop_domain("some-shoppe-over-the-rainbow.myshopify.io")
end

test "convert unified admin to old domain" do
trailing_forward_slash_url = "https://admin.shopify.com/store/store-name/"
unified_admin_url = "https://admin.shopify.com/store/store-name"

expected = "store-name.myshopify.com"

assert_equal expected, ShopifyApp::Utils.sanitize_shop_domain(trailing_forward_slash_url)
assert_equal expected, ShopifyApp::Utils.sanitize_shop_domain(unified_admin_url)
end

["myshop.com", "myshopify.com", "shopify.com", "two words", "store.myshopify.com.evil.com",
"/foo/bar", "foo.myshopify.io.evil.ru",].each do |bad_url|
test "sanitize_shop_domain for a non-myshopify URL (#{bad_url})" do
Expand Down