-
Notifications
You must be signed in to change notification settings - Fork 162
Add CLI token support for app management and BP API #5604
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
Add CLI token support for app management and BP API #5604
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
9ae7ebd
to
2a0f42d
Compare
Coverage report
Show files with reduced coverage 🔻
Test suite run success2213 tests passing in 961 suites. Report generated by 🧪jest coverage report action from 68b53f6 |
2a0f42d
to
ce7514a
Compare
7692bd1
to
a437d4f
Compare
87d5eda
to
1093c77
Compare
/snapit |
This comment has been minimized.
This comment has been minimized.
1093c77
to
a0d5b24
Compare
packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts
Outdated
Show resolved
Hide resolved
This will break old CLI tokens only if they try to access the app-management API right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎩 'ed and works, left two small comments but pre-approving, feel free to merge once those are addressed :)
e6b204f
to
6163dea
Compare
6163dea
to
4d86540
Compare
ad547ab
to
03d7671
Compare
packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Ryan DJ Lee <[email protected]> Co-authored-by: Zoey Lan <[email protected]>
03d7671
to
68b53f6
Compare
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/public/node/context/local.d.ts@@ -25,13 +25,6 @@ export declare function isDevelopment(env?: NodeJS.ProcessEnv): boolean;
* @returns True if SHOPIFY_FLAG_VERBOSE is truthy or the flag --verbose has been passed.
*/
export declare function isVerbose(env?: NodeJS.ProcessEnv): boolean;
-/**
- * It returns true if the App Management API is disabled.
- * This should only be relevant when using a Partners token.
- *
- * @returns True if the App Management API is disabled.
- */
-export declare function isAppManagementDisabled(): boolean;
/**
* Returns true if the environment in which the CLI is running is either
* a local environment (where dev is present) or a cloud environment (spin).
packages/cli-kit/dist/private/node/session/exchange.d.ts@@ -26,15 +26,33 @@ export declare function exchangeAccessForApplicationTokens(identityToken: Identi
*/
export declare function refreshAccessToken(currentToken: IdentityToken): Promise<IdentityToken>;
/**
- * Given a custom CLI token passed as ENV variable, request a valid partners API token
+ * Given a custom CLI token passed as ENV variable, request a valid Partners API token
* This token does not accept extra scopes, just the cli one.
- * @param token - The CLI token passed as ENV variable
+ * @param token - The CLI token passed as ENV variable
* @returns An instance with the application access tokens.
*/
export declare function exchangeCustomPartnerToken(token: string): Promise<{
accessToken: string;
userId: string;
}>;
+/**
+ * Given a custom CLI token passed as ENV variable, request a valid App Management API token
+ * @param token - The CLI token passed as ENV variable
+ * @returns An instance with the application access tokens.
+ */
+export declare function exchangeCliTokenForAppManagementAccessToken(token: string): Promise<{
+ accessToken: string;
+ userId: string;
+}>;
+/**
+ * Given a custom CLI token passed as ENV variable, request a valid Business Platform API token
+ * @param token - The CLI token passed as ENV variable
+ * @returns An instance with the application access tokens.
+ */
+export declare function exchangeCliTokenForBusinessPlatformAccessToken(token: string): Promise<{
+ accessToken: string;
+ userId: string;
+}>;
type IdentityDeviceError = 'authorization_pending' | 'access_denied' | 'expired_token' | 'slow_down' | 'unknown_failure';
/**
* Given a deviceCode obtained after starting a device identity flow, request an identity token.
packages/cli-kit/dist/private/node/session/scopes.d.ts@@ -13,4 +13,10 @@ export declare function allDefaultScopes(extraScopes?: string[]): string[];
* @param extraScopes - custom user-defined scopes
* @returns Array of scopes
*/
-export declare function apiScopes(api: API, extraScopes?: string[]): string[];
\ No newline at end of file
+export declare function apiScopes(api: API, extraScopes?: string[]): string[];
+/**
+ * Returns specific scopes required for token exchange with the given API.
+ * @param api - API to get the scopes for
+ * @returns Array of transformed scopes
+ */
+export declare function tokenExchangeScopes(api: API): string[];
\ No newline at end of file
|
WHY are these changes introduced?
Closes
WHAT is this pull request doing?
Add support to use the CLI token for app management API
isAppManagementDisabled()
function that disables App Management API if a CLI Token is providedServiceAccount
userUserInfo
query to get the first 2 organizations the user/CLI token service account belongs toPartners API
,BP API
andApp Management API
, the token exchange requests will fail if the CLI token does not contain enough scopes.How to test your changes?
Steps
20250414215916
npm i -g @shopify/[email protected] --@shopify:registry=https://registry.npmjs.org
Tested flows
✅ With CLI Token,
shopify app config link
a Partners app✅ With CLI Token,
shopify app config link
a dev dash app✅ With CLI Token,
shopify app deploy
a dev dash app✅ With CLI Token,
shopify app deploy
a Partners app✅ With a user session,
shopify app config link
a Partners app✅ With a user session,
shopify app config link
a dev dash app✅ With a user session,
shopify app deploy
a dev dash app✅ With a user session,
shopify app deploy
a Partners app✅ With CLI token,

shopify app info
to display a Partners app✅ With CLI token,

shopify app info
to display a dev dash appPost-release steps
Measuring impact
How do we know this change was effective? Please choose one:
Checklist