Repository navigation
Never use saved logins in store info while the service account token is set - #8899
Merged
Merged
Conversation
…is set `shopify store info` reads the login saved on this machine for the store before asking the Business Platform. A saved preview store session answers on its own, and a saved `shopify store auth` login is the fallback when the Business Platform can't find the store. With SHOPIFY_SERVICE_ACCOUNT_TOKEN set, either one makes the command answer as whoever saved that login instead of as the service account. While the token is set, store info now skips the saved login entirely: it returns what the Business Platform finds, or the Business Platform's error. `shopify store open` gets its store from store info, so it follows. Adds `usingServiceAccountToken()` to cli-kit's session module, next to `ensureNoServiceAccountToken()`, which now uses it. Co-authored-by: Eddie Gao <eddie.gao@shopify.com>
3 of 4 tasks
cli-kit's boolean helpers are named is* or has* (isCI, isTerminalInteractive, hasGit). The new helper is public API, and renaming a public export after a release counts as a breaking change, so name it to match before it ships. Co-authored-by: Eddie Gao <eddie.gao@shopify.com>
Contributor
Differences in type declarationsWe 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:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/private/node/constants.d.ts@@ -8,7 +8,7 @@ export declare const environmentVariables: {
env: string;
noAnalytics: string;
optOutInstrumentation: string;
- organizationAutomationToken: string;
+ serviceAccountToken: string;
appAutomationToken: string;
partnersToken: string;
runAsUser: string;
packages/cli-kit/dist/public/node/environment.d.ts@@ -11,9 +11,9 @@
export declare function getEnvironmentVariables(): NodeJS.ProcessEnv;
/**
* Returns the automation token the CLI authenticates with, from the first of these variables that is set:
- * SHOPIFY_ORGANIZATION_AUTOMATION_TOKEN, SHOPIFY_APP_AUTOMATION_TOKEN, or the deprecated SHOPIFY_CLI_PARTNERS_TOKEN.
+ * SHOPIFY_SERVICE_ACCOUNT_TOKEN, SHOPIFY_APP_AUTOMATION_TOKEN, or the deprecated SHOPIFY_CLI_PARTNERS_TOKEN.
*
- * Returns undefined when the variables can't be used (an empty value, or the organization variable set alongside
+ * Returns undefined when the variables can't be used (an empty value, or the service account variable set alongside
* another one). Callers then fall back to the login flow, which reports the problem instead of logging in.
*
* @returns The automation token, or undefined if there is no usable one.
packages/cli-kit/dist/public/node/session.d.ts@@ -148,15 +148,24 @@ export interface EnsureAuthenticatedBusinessPlatformOptions extends EnsureAuthen
*/
export declare function ensureAuthenticatedBusinessPlatform(scopes?: BusinessPlatformScope[], options?: EnsureAuthenticatedBusinessPlatformOptions): Promise<string>;
/**
- * Fails when SHOPIFY_ORGANIZATION_AUTOMATION_TOKEN is set, for commands that can't run with that token.
+ * Whether SHOPIFY_SERVICE_ACCOUNT_TOKEN is set, which makes it the automation token the CLI authenticates with.
*
- * Organization automation tokens can't log in as a user or call a store's Admin API, so commands that need either
+ * True even when it's empty or set together with another automation token variable. Commands use this to skip logins
+ * saved on this machine, and authentication then reports any problem with the variables.
+ *
+ * @returns True when SHOPIFY_SERVICE_ACCOUNT_TOKEN is set.
+ */
+export declare function isServiceAccountTokenSet(): boolean;
+/**
+ * Fails when SHOPIFY_SERVICE_ACCOUNT_TOKEN is set, for commands that can't run with that token.
+ *
+ * Service account tokens can't log in as a user or call a store's Admin API, so commands that need either
* refuse to run instead of quietly using the person's own login. `ensureAuthenticated` runs this check before any
* login. Commands that run on a login saved by `shopify store auth` call it before loading that login.
*
- * @throws AbortError when SHOPIFY_ORGANIZATION_AUTOMATION_TOKEN is set.
+ * @throws AbortError when SHOPIFY_SERVICE_ACCOUNT_TOKEN is set.
*/
-export declare function ensureNoOrganizationAutomationToken(): void;
+export declare function ensureNoServiceAccountToken(): void;
/**
* Logout from Shopify.
*
packages/cli-kit/dist/private/node/session/automation-token.d.ts@@ -4,7 +4,7 @@ interface AutomationTokenVariablesProblem {
}
/**
* Returns the name of the automation token variable the CLI authenticates with: the first one that is set, in
- * the order SHOPIFY_ORGANIZATION_AUTOMATION_TOKEN, SHOPIFY_APP_AUTOMATION_TOKEN, SHOPIFY_CLI_PARTNERS_TOKEN.
+ * the order SHOPIFY_SERVICE_ACCOUNT_TOKEN, SHOPIFY_APP_AUTOMATION_TOKEN, SHOPIFY_CLI_PARTNERS_TOKEN.
*
* A variable set to an empty string still counts as set, so `automationTokenVariablesProblem` can report it.
*
@@ -16,7 +16,7 @@ export declare function automationTokenVariable(env?: NodeJS.ProcessEnv): string
* Explains why the automation token variables can't be used, so a misconfigured environment fails instead of
* falling back to the logged-in user.
*
- * - SHOPIFY_ORGANIZATION_AUTOMATION_TOKEN can't be set together with SHOPIFY_APP_AUTOMATION_TOKEN or
+ * - SHOPIFY_SERVICE_ACCOUNT_TOKEN can't be set together with SHOPIFY_APP_AUTOMATION_TOKEN or
* SHOPIFY_CLI_PARTNERS_TOKEN.
* - The selected variable can't be empty.
*
|
This was referenced Oct 14, 2026
alexanderMontague
approved these changes
Oct 14, 2026
isaacroldan
reviewed
Oct 15, 2026
| const storedSession = getCurrentStoredStoreAppSession(store) | ||
| // A service account token never uses logins saved on this machine: no preview store session, and no fallback to a | ||
| // `shopify store auth` login when the Business Platform can't find the store. | ||
| const storedSession = isServiceAccountTokenSet() ? undefined : getCurrentStoredStoreAppSession(store) |
Contributor
There was a problem hiding this comment.
does this apply to other store commands/flows? or only here?
Contributor
Author
There was a problem hiding this comment.
Only here; store info was the last command that both accepts the token and can read a saved login
isaacroldan
approved these changes
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of shop/issues-develop#24007 · Builds on #8898
TL;DR: While
SHOPIFY_SERVICE_ACCOUNT_TOKENis set,shopify store info(andshopify store open, which builds on it) never reads a login saved on this machine. It returns what the Business Platform finds for the service account, or the Business Platform's error. Nothing changes when the token isn't set.SHOPIFY_SERVICE_ACCOUNT_TOKENstore info/store opennever use a saved login while the token is set ← this oneservice_account_tokenas the auth methodSHOPIFY_APP_AUTOMATION_TOKENandSHOPIFY_CLI_PARTNERS_TOKENWHY are these changes introduced?
store infochecks for a login saved on this machine for the store before asking the Business Platform:shopify store authlogin is the fallback when the Business Platform can't find the store, or would need to prompt.With the service account token set, either path makes the command answer as whoever saved that login rather than as the service account. An agent or CI job could then see a store the token can't reach, and never get the error that says so. The tech doc's noninteractive command contract lists this as "no cached Admin/preview fallback" for
store infoandstore open.The other store commands that read saved logins (
store execute,store bulk,store graphiql) already refuse while the token is set (#8731).store authdeliberately ignores the token.store infowas the last one that could still use a saved login.WHAT is this pull request doing?
store info: when the token is set,getStoreInfotreats the store as having no saved login. That one line skips the preview path, sends the Business Platform lookup withnoPrompt: false(the token never prompts), and turns off the fallback. So a Business Platform miss surfaces as the Business Platform's error.store open: no code change. It gets the store fromgetStoreInfo.isServiceAccountTokenSet()next toensureNoServiceAccountToken(), which now uses it. It's named like cli-kit's other boolean helpers (isCI,hasGit), because a public export can't be renamed after release without a breaking change. It's true whenever the variable is set, even when it's empty or conflicts with another variable. In that case the command still skips saved logins, and authentication reports the problem.How to manually test your changes?
With a saved login for a store (
shopify store auth --store <store> --scopes read_products), and any value in the token:Both fail at the token exchange ("The custom token provided can't be used for the Business Platform API"). They don't print the store's details or open it from the saved login. Without the variable, both behave as on
main.Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add