Skip to content

Fix store auth scope parsing for space-separated input#7258

Merged
RyanDJLee merged 5 commits intomainfrom
04-13-fix_store_auth_scope_parsing_for_space-separated_input
Apr 13, 2026
Merged

Fix store auth scope parsing for space-separated input#7258
RyanDJLee merged 5 commits intomainfrom
04-13-fix_store_auth_scope_parsing_for_space-separated_input

Conversation

@RyanDJLee
Copy link
Copy Markdown
Contributor

@RyanDJLee RyanDJLee commented Apr 13, 2026

Summary

Fixes shopify store auth failing with "Shopify granted fewer scopes than were requested" when scope input arrives space-separated instead of comma-separated.

  • parseStoreAuthScopes split on commas only, but space-separated input (e.g. "read_products read_inventory") was treated as a single unrecognized scope
  • The server-side parser (Access::ScopeSet.parse_scopes) handles both delimiters via /[ ,]/ — the CLI parser now matches that behavior

Root cause

A partner's CLI invocation delivered space-separated scopes to parseStoreAuthScopes. The exact shell-level cause is unknown — possibly typed without commas, or a script/wrapper issue. The CLI's .split(',') produced ["read_products read_inventory"] (one element). The server parsed both formats correctly and returned scope: "read_products,read_inventory". The CLI then failed validation because the single requested scope "read_products read_inventory" wasn't in the granted set {"read_products", "read_inventory"}.

Confirmed via partner verbose logs showing with scopes read_products read_inventory (no comma in scopes.join(',') output, proving a single-element array).

Slack thread: https://shopify.slack.com/archives/C07UJ7UNMTK/p1776085829940879

Changes

  • scopes.ts: .split(',').split(/[ ,]+/) to handle both comma and space delimiters, matching the server-side regex
  • Removed dead .trim() — splitting on /[ ,]+/ cannot produce elements with leading/trailing whitespace
  • scopes.test.ts: new tests covering space-separated input, mixed delimiters, and space-separated granted scopes through resolveGrantedScopes

Test plan

  • Existing comma-separated test still passes (no regressions)
  • New test parseStoreAuthScopes splits space-separated scopes fails before fix, passes after
  • All 70 tests across 9 auth test files pass
  • Manual: shopify store auth --scopes read_products,read_inventory on Windows PowerShell

Copy link
Copy Markdown
Contributor Author

RyanDJLee commented Apr 13, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@RyanDJLee RyanDJLee requested a review from dmerand April 13, 2026 14:13
@RyanDJLee RyanDJLee marked this pull request as ready for review April 13, 2026 14:17
@RyanDJLee RyanDJLee requested a review from a team as a code owner April 13, 2026 14:17
Copilot AI review requested due to automatic review settings April 13, 2026 14:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the CLI’s store auth scope parsing to handle Windows PowerShell’s space-separated argument transformation, preventing false “granted fewer scopes” failures after OAuth.

Changes:

  • Update parseStoreAuthScopes to split scopes on both whitespace and commas.
  • Add unit tests for space-separated and mixed-delimiter scope inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/cli/src/cli/services/store/auth/scopes.ts Broadens scope parsing to accept space- and comma-delimited input.
packages/cli/src/cli/services/store/auth/scopes.test.ts Adds coverage for new parsing behavior and related grant-resolution scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dmerand
Copy link
Copy Markdown
Contributor

dmerand commented Apr 13, 2026

One thing I’d still like covered before merge: this was a shell/input-boundary bug, but the new tests stay at the scopes.ts helper level.

The original failure path was broader: authenticateStoreWithApp(...) parsed space-separated requested scopes, built the PKCE auth request, and later compared requested vs granted scopes and threw "Shopify granted fewer scopes than were requested."

Could we either:

  1. add a service-level regression in packages/cli/src/cli/services/store/auth/index.test.ts with input like scopes: 'read_products read_inventory' and a token response like scope: 'read_products,read_inventory', asserting the flow succeeds (and ideally that the auth URL/session scopes normalize correctly), or
  2. check off the manual Windows PowerShell repro in the test plan?

I think either would give us a much stronger cross-OS confidence story than helper tests alone.

@RyanDJLee RyanDJLee force-pushed the 04-13-fix_store_auth_scope_parsing_for_space-separated_input branch from b08580c to f4c0785 Compare April 13, 2026 14:49
@RyanDJLee RyanDJLee changed the base branch from main to 04-13-regenerate_graphql_codegen April 13, 2026 15:41
@RyanDJLee RyanDJLee force-pushed the 04-13-fix_store_auth_scope_parsing_for_space-separated_input branch from ebafe03 to 569d32a Compare April 13, 2026 15:41
@RyanDJLee RyanDJLee changed the base branch from 04-13-regenerate_graphql_codegen to main April 13, 2026 15:58
@RyanDJLee RyanDJLee force-pushed the 04-13-fix_store_auth_scope_parsing_for_space-separated_input branch from 569d32a to a24ed11 Compare April 13, 2026 15:58
@RyanDJLee RyanDJLee changed the base branch from main to dlm-graphql-codegen April 13, 2026 16:49
@RyanDJLee RyanDJLee force-pushed the 04-13-fix_store_auth_scope_parsing_for_space-separated_input branch from a24ed11 to a373448 Compare April 13, 2026 16:49
@github-actions
Copy link
Copy Markdown
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/node-package-manager.d.ts
@@ -68,6 +68,10 @@ export declare function packageManagerFromUserAgent(env?: NodeJS.ProcessEnv): Pa
  * @returns The dependency manager
  */
 export declare function getPackageManager(fromDirectory: string): Promise<PackageManager>;
+export declare function packageManagerBinaryCommandForDirectory(directory: string, binary: string, ...args: string[]): Promise<{
+    command: string;
+    args: string[];
+}>;
 interface InstallNPMDependenciesRecursivelyOptions {
     /**
      * The dependency manager to use to install the dependencies.

@RyanDJLee RyanDJLee changed the base branch from dlm-graphql-codegen to graphite-base/7258 April 13, 2026 17:04
@RyanDJLee RyanDJLee force-pushed the graphite-base/7258 branch from ac02da2 to a21a899 Compare April 13, 2026 17:04
@RyanDJLee RyanDJLee changed the base branch from graphite-base/7258 to main April 13, 2026 17:04
@RyanDJLee RyanDJLee changed the base branch from main to graphite-base/7258 April 13, 2026 17:08
@RyanDJLee RyanDJLee force-pushed the graphite-base/7258 branch from b72644f to ac02da2 Compare April 13, 2026 17:08
@RyanDJLee RyanDJLee changed the base branch from graphite-base/7258 to dlm-graphql-codegen April 13, 2026 17:08
RyanDJLee and others added 4 commits April 13, 2026 13:48
parseStoreAuthScopes splits on commas only, but Windows PowerShell can
transform comma-separated CLI args into space-separated strings before
they reach Node.js. This causes "read_products read_inventory" to be
treated as one unrecognized scope, triggering a false "fewer scopes
than requested" error.

Split on /[\s,]+/ instead — matching Core's own ScopeSet.parse_scopes
which already handles both delimiters.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Narrow regex from /[\s,]+/ to /[ ,]+/ to match server-side
  Access::ScopeSet.parse_scopes behavior (space and comma only)
- Remove dead .trim() — splitting on /[ ,]+/ can't produce
  elements with leading/trailing whitespace
- Fix test that claimed to cover space-separated parsing but
  actually passed comma-separated input (exercising no new code)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collapse split/filter chain to single line to satisfy prettier.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Exercises the full authenticateStoreWithApp flow with space-separated
input ('read_products read_inventory') and comma-separated server
response, asserting the scopes resolve correctly and persist to the
session store. Addresses review feedback from dmerand.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@RyanDJLee RyanDJLee changed the base branch from dlm-graphql-codegen to main April 13, 2026 17:48
…update

Upstream schema updated JSDoc comments for Operator, ShopFilterField,
and ShopFilterInput types (added IN operator documentation).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@RyanDJLee RyanDJLee force-pushed the 04-13-fix_store_auth_scope_parsing_for_space-separated_input branch from a373448 to ad4b9fa Compare April 13, 2026 17:49
@RyanDJLee RyanDJLee added this pull request to the merge queue Apr 13, 2026
Copy link
Copy Markdown
Contributor

dmerand commented Apr 13, 2026

/snapit

@github-actions
Copy link
Copy Markdown
Contributor

🫰✨ Thanks @dmerand! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

npm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260413182601

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

Merged via the queue into main with commit 9dfe97c Apr 13, 2026
64 of 67 checks passed
@RyanDJLee RyanDJLee deleted the 04-13-fix_store_auth_scope_parsing_for_space-separated_input branch April 13, 2026 18:31
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