Shopify / shopify-cli

Shopify CLI helps you build against the Shopify platform faster.
https://shopify.dev/tools/cli
Other
1.01k stars 202 forks source link

CLI crashes if there is no program to handle the protocol on login #1425

Closed brett-uaudio closed 2 years ago

brett-uaudio commented 3 years ago

Issue summary

Write a short description of the issue here ↓

The CLI crashes on login if xdg-open can't find a suitable program to handle https(?)

Expected behavior

What do you think should happen?

I should be able to login successfully on a remote machine when there is no suitable program available to xdg-open by pasting a URL that gets printed to the console in a local machine's browser with a suitable tunnel or other way to get the localhost:3456 call back to the remote server with the running CLI. This is part of setting up a Bamboo CI plan. We successfully got this to work in a Docker container, probably because it didn't have xdg-open installed.

Actual behavior

What actually happens?

The CLI crashes and prints the flow URL to the console.

Steps to reproduce the problem

  1. Have a remote Linux machine with xdg-open installed but no programs to handle the protocol (I assume it's https, but I'm not sure).
  2. Run shopify login --shop=SHOP.
  3. The CLI will crash and print out the URL for the flow.

Reduced test case

Specifications

mkevinosullivan commented 3 years ago

@brett-uaudio Please share the compete output from the CLI when it crashes.

axis80 commented 2 years ago

I'm running into this exact same issue with Shopify CLI 2.12.0, running on an Ubuntu 21.10 server. I am connected to the machine through SSH, so there is no GUI and therefore no Firefox/Chrome/Edge browser. (And, I can't use a text-based CLI web browser, because Shopify's login page requires Javascript for the Captcha.)

In older versions of Shopify CLI, if you executed the shopify login command and there was no system browser defined, it would output a message such as "Please open this URL in your browser" along with an OAuth URL. The CLI would then start an HTTP server listening on http://127.0.0.1:3456/ and waiting for authentication to complete. I could load the OAuth URL on my desktop PC, then copy the resulting callback/redirect URL to my clipboard, open a new CLI window on the Ubuntu server, and load the URL with a command like wget "http://127.0.0.1:3456/foo" to complete login. It was a little clunky, but it worked.

This behavior has apparently changed. Shopify CLI immediately exits with an error, and without starting an HTTP server on port 3456.

Here is sample output (with some of the token values modified out of an abundance of security caution):

derrick@myubuntu:/var/www/vhosts/www.example.com/myapp$ shopify login
/usr/bin/xdg-open: 869: www-browser: not found
/usr/bin/xdg-open: 869: links2: not found
/usr/bin/xdg-open: 869: elinks: not found
/usr/bin/xdg-open: 869: links: not found
/usr/bin/xdg-open: 869: lynx: not found
/usr/bin/xdg-open: 869: w3m: not found
xdg-open: no method available for opening 'https://accounts.shopify.com/oauth/authorize?client_id=fdbb6753-d357-4927-8e38-908d34cfd7e3&scope=openid+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshop.admin.graphql+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshop.admin.themes+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fpartners.collaborator-relationships.readonly+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshop.storefront-renderer.devtools+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fpartners.app.cli.access&redirect_uri=http%3A%2F%2F127.0.0.1%3A3456&state=13dc35407fd46cce9a768dfc3de02716eeb42e231c85fe24c3c660d46ef1&response_type=code&code_challenge=3zKkHj8eeUJbYudGsg303aCRKi9AQqm3DLc_g6rHTIc&code_challenge_method=S256'
┏━━ Error ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ ✗ System call failed: xdg-open https://accounts.shopify.com/oauth/authorize?client_id=fdbb6753-d357-4927-8e38-908d34cfd7e3&scope=openid+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshop.admin.graphql+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshop.admin.themes+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fpartners.collaborator-relationships.readonly+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshop.storefront-renderer.devtools+https%3A%2F%2Fapi.shopify.com%2Fauth%2Fpartners.app.cli.access&redirect_uri=http%3A%2F%2F127.0.0.1%3A3456&state=13dc35407fd46cce9a768dfc3de02716eeb42e231c85fe24c3c660d46ef1&response_type=code&code_challenge=3zKkHj8eeUJbYudGsg303aCRKi9AQqm3DLc_g6rHTIc&code_challenge_method=S256
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

It would be great if you could a) reopen this issue; and b) revert to the previous behavior of outputting the URL and listening on port 3456 for the login to complete.

axis80 commented 2 years ago

I would also point out that Heroku handles this with a --interactive login switch. So, when you specify this command, they will prompt for username and password at the command line:

heroku login --interactive

dsychin commented 2 years ago

I am facing the same issue where my development environment is running Linux on Windows with WSL. There is no browser inside WSL but I also can't use the link the error spits out because the callback url does not work since the command just exits immediately.

Update: I managed to fix it by uninstalling xdg-open. It seems that whatever it fallback to if xdg-open doesn't exist works if your environment does not have a browser. Maybe the way to solve this issue is to fallback to the alternative methods if xdg-open fails.

axis80 commented 2 years ago

Wow, thanks @dsychin! I uninstalled xdg-open from my Ubuntu machine using sudo apt-get remove --auto-remove xdg-utils and that restored the old behavior. I am now able to use my clunky workaround (described above) to log in.

To be clear: it'd be ideal if the Shopify CLI team could add a shopify login --interactive login method. In the meantime, though, at least there is some sort of workaround, as clunky as it may be.

github-actions[bot] commented 2 years ago

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action.

→ If there's no activity within a week, then a bot will automatically close this.

Thanks for helping to improve Shopify's dev tooling and experience.