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

IsValidShopDomainAsync is broke. #331

Closed
Pokoto opened this Issue Feb 6, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@Pokoto
Copy link

Pokoto commented Feb 6, 2019

Hi,

I experienced issues with my App and discovered that since a couple of days,
IsValidShopDomainAsync stopped working - always returns false.

At first sight, looks likely Shopify changed the backend behavior
(maybe a redirect on /admin or is checking for other headers...)

Testing against the domain home (which requires to set a user agent)
seems to do the trick.

Here is a quick fix.

public static async Task IsValidShopDomainAsync(string url) {

        var uri = ShopifyService.BuildShopUri(url, false);

        using (var client = new HttpClient())
        {

            string UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0";
            var msg = new HttpRequestMessage(HttpMethod.Head, uri);
            msg.Headers.Add("User-Agent", UserAgent);

            using (msg)
            {
                try
                {
                    var response = await client.SendAsync(msg);

                    return response.Headers.Any(h => h.Key.Equals("X-ShopId", StringComparison.OrdinalIgnoreCase));
         
                }
                catch (HttpRequestException)
                {
                    return false;
                }
            }
        }
    }

Best,
Andrea

@nozzlegear nozzlegear added the bug label Feb 6, 2019

@nozzlegear

This comment has been minimized.

Copy link
Owner

nozzlegear commented Feb 6, 2019

Thanks for reporting this Andrea, I've been seeing the same thing off and on starting about a week ago. Sometimes it works and sometimes it doesn't. This is an undocumented "feature" that the package has been using, so unfortunately there's no warning when Shopify makes a change that might break it. I'll get it fixed!

@Mat-Kay

This comment has been minimized.

Copy link

Mat-Kay commented Feb 6, 2019

I am also seeing this as of today. Fiddler is showing a chain of redirects, ending in a 404:

HEAD /admin 
	-> 303 See Other, Location: Location: https://***.myshopify.com/admin/auth/login
HEAD /admin/auth/login 
	-> 302 Found, Location: https://app.shopify.com/services/login/identity?destination_uuid=***&return_to=***&ui_locales=en&ux=shop
HEAD https://app.shopify.com/services/login/identity?destination_uuid=***&return_to=***&ui_locales=en&ux=shop 
	-> 404 Not Found

The first 2 responses include the X-ShopId header, but the final 404 does not.

@nozzlegear

This comment has been minimized.

Copy link
Owner

nozzlegear commented Feb 6, 2019

Oh I see, because they're redirecting to some kind of auth service now instead of using a login page on the shop domain. So probably best to just make a request to the root domain instead of /admin, and not follow redirects.

@nozzlegear

This comment has been minimized.

Copy link
Owner

nozzlegear commented Feb 7, 2019

Got a fix coming later this evening. Hang tight everyone!

@nozzlegear nozzlegear closed this in c1fbfe2 Feb 7, 2019

@nozzlegear

This comment has been minimized.

Copy link
Owner

nozzlegear commented Feb 7, 2019

Fixed in 4.18.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.