cli icon indicating copy to clipboard operation
cli copied to clipboard

[Bug]: Cannot skip login via browser using SHOPIFY_CLI_DEVICE_AUTH=1

Open sillycube opened this issue 1 year ago • 1 comments

Please confirm that you have:

  • [x] Searched existing issues to see if your issue is a duplicate. (If you’ve found a duplicate issue, feel free to add additional information in a comment on it.)
  • [x] Reproduced the issue in the latest CLI version.

In which of these areas are you experiencing a problem?

App

Expected behavior

I was using SHOPIFY_CLI_DEVICE_AUTH=1 to run npm run dev. Previously, it could work for login in my remote server, which couldn't open a browser GUI. After a while, I upgraded my CLI to the latest version and I couldn't login with SHOPIFY_CLI_DEVICE_AUTH=1 npm run dev. I was logged on before but I was logged out suddenly. I don't know why it was.

Is this option still working? Did I miss anything?

Actual behavior

bennychan:~/abc$ SHOPIFY_CLI_ACCESS_CODE_AUTH=1 npm run dev -- --theme 1234

dev shopify app dev --theme 1234

To run this command, log in to Shopify. 👉 Press any key to open the login page on your browser Error: spawn xdg-open ENOENT at ChildProcess._handle.onexit (node:internal/child_process:286:19) at onErrorNT (node:internal/child_process:484:16) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Verbose output

bennychan@Dev:~/myProject$ SHOPIFY_CLI_DEVICE_AUTH=1 shopify app dev --verbose 2024-09-28T10:07:21.393Z: Running command app dev 2024-09-28T10:07:21.430Z: Getting a random port... 2024-09-28T10:07:21.443Z: Random port obtained: 41035 2024-09-28T10:07:21.478Z: cloudflared already installed, skipping 2024-09-28T10:07:21.494Z: Running system process: · Command: /home/bennychan/.nvm/versions/node/v21.6.2/lib/node_modules/@shopify/cli/bin/cloudflared tunnel --url http://localhost:41035 --no-autoupdate · Working directory: /home/bennychan/myProject

2024-09-28T10:07:21.513Z: Reading cached app information for directory /home/bennychan/myProject... 2024-09-28T10:07:21.515Z: 2024-09-28T10:07:21Z INF Thank you for trying Cloudflare Tunnel. Doing so, without a Cloudflare account, is a quick way to experiment and try it out. However, be aware that these account-less Tunnels have no uptime guarantee. If you intend to use Tunnels in production you should use a pre-created named tunnel by following: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps 2024-09-28T10:07:21Z INF Requesting new quick Tunnel on trycloudflare.com...

2024-09-28T10:07:21.521Z: Reading the content of file at shopify.app.toml... 2024-09-28T10:07:21.534Z: Reading the content of file at shopify.app.toml... 2024-09-28T10:07:21.546Z: Reading the content of file at shopify.app.myProject.toml... 2024-09-28T10:07:21.624Z: Reading cached app information for directory /home/bennychan/myProject... 2024-09-28T10:07:21.626Z: Reading cached app information for directory /home/bennychan/myProject... 2024-09-28T10:07:21.629Z: Reading cached app information for directory /home/bennychan/myProject... 2024-09-28T10:07:21.632Z: Reading the content of file at shopify.app.toml... 2024-09-28T10:07:21.635Z: Reading the content of file at shopify.app.toml... 2024-09-28T10:07:21.644Z: Reading the content of file at shopify.app.myProject.toml... 2024-09-28T10:07:21.712Z: Ensuring that the user is authenticated with the Partners API with the following scopes: []

2024-09-28T10:07:21.713Z: Getting session store... 2024-09-28T10:07:21.715Z: Validating existing session against the scopes: [ "openid", "https://api.shopify.com/auth/shop.admin.graphql", "https://api.shopify.com/auth/shop.admin.themes", "https://api.shopify.com/auth/partners.collaborator-relationships.readonly", "https://api.shopify.com/auth/shop.storefront-renderer.devtools", "https://api.shopify.com/auth/partners.app.cli.access", "https://api.shopify.com/auth/destinations.readonly" ] For applications: { "partnersApi": { "scopes": [] } }

2024-09-28T10:07:21.716Z: Initiating the full authentication flow... 2024-09-28T10:07:21.717Z: Requesting device authorization code... 2024-09-28T10:07:21.721Z: Sending POST request to URL https://accounts.shopify.com/oauth/device_authorization With request headers:

  • User-Agent: Shopify CLI; v=3.67.2
  • Keep-Alive: timeout=30
  • Sec-CH-UA-PLATFORM: linux
  • Content-Type: application/json
  • Content-type: application/x-www-form-urlencoded

2024-09-28T10:07:22.109Z: Request to https://accounts.shopify.com/oauth/device_authorization completed in 386 ms With response headers:

  • cache-control: no-cache, no-store, private, must-revalidate, max-age=0
  • content-type: application/json; charset=utf-8
  • etag: W/"869f07dcab045b5fe5d49eae0737acf1"
  • server-timing: processing;dur=66, socket_queue;dur=1.746, edge;dur=1.024, util;dur=0.0, cfRequestDuration;dur=326.999903
  • x-request-id: 5225d8e1-7038-4ee6-92f1-3c321c97e390-1727518041

2024-09-28T10:07:22.116Z: Received device authorization code: { "verification_uri": "https://shopify.com/activate", "verification_uri_complete": "https://accounts.shopify.com/activate-with-code?device_code%5Buser_code%5D=SZWQ-BRVQ", "expires_in": 599, "interval": 5, "device_code": "e75f772e-fc22-47d1-98e9-0ba5e80e23d2", "user_code": "SZWQ-BRVQ" }

To run this command, log in to Shopify. User verification code: SZWQ-BRVQ 👉 Press any key to open the login page on your browser 2024-09-28T10:07:26.255Z: 2024-09-28T10:07:26Z INF +--------------------------------------------------------------------------------------------+ 2024-09-28T10:07:26Z INF | Your quick Tunnel has been created! Visit it at (it may take some time to be reachable): | 2024-09-28T10:07:26Z INF | https://popular-prerequisite-aud-pod.trycloudflare.com | 2024-09-28T10:07:26Z INF +--------------------------------------------------------------------------------------------+

2024-09-28T10:07:26.256Z: 2024-09-28T10:07:26Z INF Cannot determine default configuration path. No file [config.yml config.yaml] in [~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp /etc/cloudflared /usr/local/etc/cloudflared] 2024-09-28T10:07:26Z INF Version 2024.8.2 2024-09-28T10:07:26Z INF GOOS: linux, GOVersion: go1.22.2, GoArch: amd64 2024-09-28T10:07:26Z INF Settings: map[ha-connections:1 no-autoupdate:true protocol:quic url:http://localhost:41035]

2024-09-28T10:07:26.256Z: 2024-09-28T10:07:26Z INF Generated Connector ID: 2682ce3b-65c9-4081-8f0f-fd5eaa7f17d5

2024-09-28T10:07:26.258Z: 2024-09-28T10:07:26Z INF cloudflared will not automatically update if installed by a package manager.

2024-09-28T10:07:26.275Z: 2024-09-28T10:07:26Z INF Initial protocol quic 2024-09-28T10:07:26Z INF ICMP proxy will use 165.22.48.235 as source for IPv4 2024-09-28T10:07:26Z INF ICMP proxy will use fe80::6821:d4ff:feb3:9ad9 in zone eth0 as source for IPv6

2024-09-28T10:07:26.288Z: 2024-09-28T10:07:26Z INF Starting metrics server on 127.0.0.1:41205/metrics

2024-09-28T10:07:26.339Z: 2024-09-28T10:07:26Z WRN Your version 2024.8.2 is outdated. We recommend upgrading it to 2024.9.1

2024-09-28T10:07:26.928Z: 2024-09-28T10:07:26Z INF Registered tunnel connection connIndex=0 connection=597e3c6d-bc19-4e26-89a6-ebcdd294b4ec event=0 ip=198.41.200.53 location=sin12 protocol=quic

Reproduction steps

When I run the command SHOPIFY_CLI_DEVICE_AUTH=1 npm run dev, it shows me "👉 Press any key to open the login page on your browser". When I press any key, it shows the error.

Operating System

Ubuntu 20.04

Shopify CLI version (check your project's package.json if you're not sure)

3.67.1, local Shopify CLI. But it's still the same when I switch to global Shopify CLI

Shell

No response

Node version (run node -v if you're not sure)

v21.6.2

What language and version are you using in your application?

No response

sillycube avatar Sep 20 '24 10:09 sillycube

Also have this error when running shopify app dev inside a docker container

theo-styles-radiant avatar Sep 24 '24 08:09 theo-styles-radiant

Experiencing the same issue within a docker container

pietervandendungen avatar Oct 23 '24 12:10 pietervandendungen

@sillycube do you know which shopify cli version works with SHOPIFY_CLI_DEVICE_AUTH flag?

I just want to turn on the development mode for my app and run some automation tests with my development store in CI...it's so hard with this shopify cli.

hSATAC avatar Oct 30 '24 04:10 hSATAC

@hSATAC

Shopify CLI 3.61.0 Node version v21.6.2

sillycube avatar Oct 30 '24 04:10 sillycube

Another workaround is to add a dummy executable named xdg-open in your $PATH. Then run the shopify CLI command as usual. The CLI will log the auth URL that you can visit in your browser and complete the auth process.

ranjan-purbey avatar Nov 12 '24 16:11 ranjan-purbey

@ranjan-purbey

Thanks for your suggestion. Can you give me an example on how to add the dummy executable? Or what command to run?

sillycube avatar Nov 13 '24 08:11 sillycube

@ranjan-purbey

Thanks for your suggestion. Can you give me an example on how to add the dummy executable? Or what command to run?

For example, you can create an executable like this:

mkdir ~/tmp-bin && export PATH=$PATH:~/tmp-bin && echo "#!/bin/sh" > ~/tmp-bin/xdg-open && chmod +x ~/tmp-bin/xdg-open

ranjan-purbey avatar Nov 13 '24 13:11 ranjan-purbey

@ranjan-purbey Thanks for your suggestion. Can you give me an example on how to add the dummy executable? Or what command to run?

For example, you can create an executable like this:

mkdir ~/tmp-bin && export PATH=$PATH:~/tmp-bin && echo "#!/bin/sh" > ~/tmp-bin/xdg-open && chmod +x ~/tmp-bin/xdg-open

This script works well; however, I recommend Bash users replace the " with '. Otherwise, you'll get an error in the console.

thosakwe avatar Dec 18 '24 15:12 thosakwe

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.

P.S. You can learn more about why we stale issues here.

github-actions[bot] avatar Jan 30 '25 03:01 github-actions[bot]

This issue is still not solved ? I am facing this problem when trying to run npm run deploy

saitama-on avatar Oct 04 '25 16:10 saitama-on