Skip to content

feat(account-api): support client credentials auth via env vars#918

Merged
Soner (shyim) merged 4 commits intomainfrom
feat/account-client-credentials-auth
Mar 18, 2026
Merged

feat(account-api): support client credentials auth via env vars#918
Soner (shyim) merged 4 commits intomainfrom
feat/account-client-credentials-auth

Conversation

@shyim
Copy link
Member

Summary

  • Add OAuth2 client credentials flow for non-interactive authentication using SHOPWARE_CLI_ACCOUNT_CLIENT_ID and SHOPWARE_CLI_ACCOUNT_CLIENT_SECRET environment variables
  • Enable CI/CD pipelines to authenticate with the Shopware Account API without user interaction
  • Add SHOPWARE_CLI_OIDC_ENDPOINT env var override for custom OIDC endpoints

Auth priority order

  1. Token cache (existing valid token)
  2. Client credentials via SHOPWARE_CLI_ACCOUNT_CLIENT_ID + SHOPWARE_CLI_ACCOUNT_CLIENT_SECRET (new)
  3. Legacy email/password via SHOPWARE_CLI_ACCOUNT_EMAIL + SHOPWARE_CLI_ACCOUNT_PASSWORD
  4. Interactive OAuth2 browser login

Test plan

  • Unit test for client credentials flow with mock token server
  • Manual test with real client ID/secret against staging

…I/CD

Allow non-interactive authentication using SHOPWARE_CLI_ACCOUNT_CLIENT_ID
and SHOPWARE_CLI_ACCOUNT_CLIENT_SECRET environment variables, enabling
OAuth2 client credentials flow for automated CI/CD pipelines.
Copilot AI review requested due to automatic review settings March 18, 2026 09:42
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

Adds non-interactive authentication options for the Shopware Account API to better support CI/CD usage, primarily via OAuth2 client credentials sourced from environment variables, plus an override for the OIDC endpoint.

Changes:

  • Add OAuth2 client-credentials login path in NewApi using SHOPWARE_CLI_ACCOUNT_CLIENT_ID / SHOPWARE_CLI_ACCOUNT_CLIENT_SECRET.
  • Add SHOPWARE_CLI_OIDC_ENDPOINT env var override for custom OIDC endpoints.
  • Add a unit test covering the client-credentials token request against a mock token server.

Reviewed changes

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

File Description
internal/account-api/oidc.go Adds client-credentials scope constant and OIDC endpoint override via env var.
internal/account-api/login.go Introduces client-credentials login flow and integrates it into auth priority.
internal/account-api/login_test.go Adds unit test validating client-credentials flow with a mock token server.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +13 to +18
tokenRequested := false

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/oauth2/token" {
tokenRequested = true

Soner (shyim) and others added 3 commits March 18, 2026 10:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Fail fast when only one of client ID/secret env vars is set
- Set AuthStyle to AuthStyleInParams to match interactive OAuth2 flow
- Use atomic.Bool for race-safe test assertions
- Add test for incomplete credentials error
@shyim Soner (shyim) merged commit 1479282 into main Mar 18, 2026
3 checks passed
@shyim Soner (shyim) deleted the feat/account-client-credentials-auth branch March 18, 2026 09:56
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.

2 participants