-
Notifications
You must be signed in to change notification settings - Fork 130
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
Client credentials flow for GraphiQL #2887
Conversation
Thanks for your contribution! Depending on what you are working on, you may want to request a review from a Shopify team:
|
d53cd7a
to
0e700d8
Compare
Coverage report
Show files with reduced coverage 🔻
Test suite run success1434 tests passing in 665 suites. Report generated by 🧪jest coverage report action from 060bd75 |
e111d36
to
0be302d
Compare
c6561a5
to
c25ec53
Compare
This comment has been minimized.
This comment has been minimized.
c25ec53
to
0b8b1ff
Compare
client_secret: apiSecret, | ||
grant_type: 'client_credentials', | ||
}) | ||
const tokenResponse = await fetch(`https://${storeFqdn}/admin/oauth/access_token?${queryString}`, { |
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.
are there any plans to have this in the @shopify/shopify-api
library?
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.
Great question for @paulomarg
I don't think it impacts our efforts, though, as there are significant advantages to eliminating the library from our code (specifically no longer requiring app scopes).
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.
I agree it's good to not have the full shopify-api dependency. Maybe worth moving it to CLI Kit though to start with?
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.
Actually, I retract what I said. This is only available on dev stores (for now), so it shouldn't be in the library.
RE cli-kit, I'm not sure offhand. Usually my inclination is to leave things in individual packages until there is a defined use case in multiple packages.
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.
FWIW, we are in the process of adding token exchange support to the library. https://github.com/Shopify/shopify-api-js/pull/1036/files#diff-b96b5dd8c43f3122c7def35d0d4a4190cfc9e2318de6f5b970c285fcb5b6ec02R29
client_secret: apiSecret, | ||
grant_type: 'client_credentials', | ||
}) | ||
const tokenResponse = await fetch(`https://${storeFqdn}/admin/oauth/access_token?${queryString}`, { |
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.
I agree it's good to not have the full shopify-api dependency. Maybe worth moving it to CLI Kit though to start with?
Using client credentials, we no longer require this code, most prominently that which updates the callback URLs, since we no longer perform an in-browser OAuth flow with a callback URL.
This was only necessary when using the `@shopify/shopify-api` package. But now we've gotten rid of it. And there is plenty you can do without scopes, so we should still enable GraphiQL.
0b8b1ff
to
53c2238
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/api/admin.d.ts@@ -9,6 +9,21 @@ import { AdminSession } from '../session.js';
* @returns The response of the query of generic type <T>.
*/
export declare function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T>;
+/**
+ * GraphQL query to retrieve all supported API versions.
+ *
+ * @param session - Shopify admin session including token and Store FQDN.
+ * @returns - An array of supported API versions.
+ */
+export declare function supportedApiVersions(session: AdminSession): Promise<string[]>;
+/**
+ * Returns the Admin API URL for the given store and version.
+ *
+ * @param store - Store FQDN.
+ * @param version - API version.
+ * @returns - Admin API URL.
+ */
+export declare function adminUrl(store: string, version: string | undefined): string;
/**
* Executes a REST request against the Admin API.
*
|
WHY are these changes introduced?
Fixes https://github.com/Shopify/develop-app-management/issues/1494
Replaces the existing, somewhat messy solution for authentication (OAuth with redirect to GraphiQL) with the client credentials flow that can happen entirely behind the scenes.
This means:
WHAT is this pull request doing?
Replaces the existing solution with a behind-the-scenes client credentials OAuth flow.
In case the user isn't logged in yet, we've added a page instructing them to click a link to install the app in a new tab. Once the app is installed, the tab will be closed and they'll be redirected to GraphiQL.
There have been a few other related changes:
@shopify/shopify-api
was removed. We are now getting API versions straight from the source of truth, and requests are being forwarded to the API in a more raw fashion. (I believe this should work the same in spin, but we should be sure of that. I know the npm package did have some special spin handling.)cli-kit
thestyle.css
asset we use to show simple pages like the post-login page.How to test your changes?
p shopify app dev --path /path/to/your/app
g
Be sure to try with the app previously installed and uninstalled.
Measuring impact
How do we know this change was effective? Please choose one:
Checklist
dev
ordeploy
have been reflected in the internal flowchart.