Skip to content

feat(api-gen): support for client_credentials grant type auth#2262

Open
mkucmus wants to merge 1 commit intomainfrom
feat/api-gen-credentials
Open

feat(api-gen): support for client_credentials grant type auth#2262
mkucmus wants to merge 1 commit intomainfrom
feat/api-gen-credentials

Conversation

@mkucmus
Copy link
Contributor

@mkucmus mkucmus commented Jan 28, 2026

Description

Added support for client_credentials grant type authentication when loading Admin API schema.

@mkucmus mkucmus requested review from Copilot and patzick January 28, 2026 10:46
@vercel
Copy link

vercel bot commented Jan 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
frontends-starter-template-extended Ready Ready Preview, Comment Jan 28, 2026 10:46am
frontends-vue-starter-template Ready Ready Preview, Comment Jan 28, 2026 10:46am
old-frontends-demo Ready Ready Preview, Comment Jan 28, 2026 10:46am
shopware-frontends-docs Ready Ready Preview, Comment Jan 28, 2026 10:46am

Request Review

Copy link
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

This PR adds support for client_credentials grant type authentication for the Admin API, providing an alternative to the existing username/password authentication method. This enables authentication using Shopware integrations instead of user credentials.

Changes:

  • Modified authentication logic to support both password and client_credentials grant types based on environment variables
  • Updated environment variable validation to conditionally check for username/password OR client credentials
  • Enhanced documentation to explain both authentication methods and their usage

Reviewed changes

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

File Description
packages/api-gen/src/apiClient.ts Added conditional logic to create credentials object based on whether SHOPWARE_ADMIN_CLIENT_SECRET is set, supporting both password and client_credentials grant types
packages/api-gen/src/commands/loadSchema.ts Modified environment variable validation to require either username/password OR client_secret for admin API authentication
packages/api-gen/README.md Added documentation for the new client_credentials authentication option with configuration examples
.changeset/heavy-bushes-open.md Added changeset describing the new feature

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

: ({
grant_type: "password",
client_id: "administration",
scope: "write",
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The field name should be "scopes" (plural), not "scope" (singular). This is inconsistent with the password grant type credentials structure used in the api-client package tests and throughout the codebase. The tests in packages/api-client/src/adminApiClientCredentials.test.ts show that password credentials use "scopes" field (lines 99, 110, 141).

Suggested change
scope: "write",
scopes: "write",

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

its done via #2261

"@shopware/api-gen": minor
---

Added support for `client_credentials` grant type authentication when loading Admin API schema. Set `SHOPWARE_ADMIN_CLIENT_SECRET` and `SHOPWARE_ADMIN_CLIENT_ID`environment variables to use integration credentials instead of username/password.
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Missing space between "SHOPWARE_ADMIN_CLIENT_ID" and "environment". Should be "SHOPWARE_ADMIN_CLIENT_ID environment variables".

Suggested change
Added support for `client_credentials` grant type authentication when loading Admin API schema. Set `SHOPWARE_ADMIN_CLIENT_SECRET` and `SHOPWARE_ADMIN_CLIENT_ID`environment variables to use integration credentials instead of username/password.
Added support for `client_credentials` grant type authentication when loading Admin API schema. Set `SHOPWARE_ADMIN_CLIENT_SECRET` and `SHOPWARE_ADMIN_CLIENT_ID` environment variables to use integration credentials instead of username/password.

Copilot uses AI. Check for mistakes.
Comment on lines +62 to +63
const hasClientCredentials = !!process.env.SHOPWARE_ADMIN_CLIENT_SECRET;
if (!hasClientCredentials) {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

When using client_credentials grant type, SHOPWARE_ADMIN_CLIENT_SECRET should be a required environment variable. Currently, the code only checks for username/password when SHOPWARE_ADMIN_CLIENT_SECRET is not set, but it doesn't validate that SHOPWARE_ADMIN_CLIENT_SECRET is actually provided when the client_credentials flow is selected. This could lead to runtime errors when trying to authenticate. Consider adding SHOPWARE_ADMIN_CLIENT_SECRET to requiredEnvVars when hasClientCredentials is true.

Suggested change
const hasClientCredentials = !!process.env.SHOPWARE_ADMIN_CLIENT_SECRET;
if (!hasClientCredentials) {
const hasClientCredentials =
process.env.SHOPWARE_ADMIN_CLIENT_SECRET !== undefined;
if (hasClientCredentials) {
requiredEnvVars.push("SHOPWARE_ADMIN_CLIENT_SECRET");
} else {

Copilot uses AI. Check for mistakes.
grant_type: "client_credentials",
client_id: process.env.SHOPWARE_ADMIN_CLIENT_ID || "administration",
client_secret: process.env.SHOPWARE_ADMIN_CLIENT_SECRET,
} as const)
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The type casting for client_credentials uses "as const" while the password grant uses "as unknown as adminOperations[...]". This inconsistency suggests a potential type safety issue. The client_credentials object should also be cast to the proper type (adminOperations["token post /oauth/token"]["body"]) to ensure type safety and consistency with the password grant type casting approach.

Suggested change
} as const)
} as unknown as adminOperations["token post /oauth/token"]["body"])

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +23
const credentials = process.env.SHOPWARE_ADMIN_CLIENT_SECRET
? ({
grant_type: "client_credentials",
client_id: process.env.SHOPWARE_ADMIN_CLIENT_ID || "administration",
client_secret: process.env.SHOPWARE_ADMIN_CLIENT_SECRET,
} as const)
: ({
grant_type: "password",
client_id: "administration",
scope: "write",
username: process.env.SHOPWARE_ADMIN_USERNAME || "",
password: process.env.SHOPWARE_ADMIN_PASSWORD || "",
} as unknown as adminOperations["token post /oauth/token"]["body"]);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The logic to determine which authentication method to use is based solely on whether SHOPWARE_ADMIN_CLIENT_SECRET is set. This could lead to unexpected behavior if a user has both password credentials (SHOPWARE_ADMIN_USERNAME, SHOPWARE_ADMIN_PASSWORD) and client credentials (SHOPWARE_ADMIN_CLIENT_SECRET) configured in their environment. Consider documenting this precedence clearly or adding a warning when both sets of credentials are present.

Copilot uses AI. Check for mistakes.
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.

1 participant