Skip to content

feat(proxy): support accessToken auth alongside apiKey#314

Open
Eyalm321 wants to merge 1 commit intogoogle-labs-code:mainfrom
Eyalm321:feat/access-token-auth
Open

feat(proxy): support accessToken auth alongside apiKey#314
Eyalm321 wants to merge 1 commit intogoogle-labs-code:mainfrom
Eyalm321:feat/access-token-auth

Conversation

@Eyalm321
Copy link
Copy Markdown

@Eyalm321 Eyalm321 commented Apr 14, 2026

Summary

  • Add accessToken as an alternative authentication method in the proxy module's Zod schema, constructor, and HTTP client
  • When accessToken is provided (via config or STITCH_ACCESS_TOKEN env var), the proxy sends Authorization: Bearer headers instead of X-Goog-Api-Key
  • Add quotaProjectId to send X-Goog-User-Project header with Bearer auth (required by Google APIs for billing/quota)
  • The proxy now accepts either apiKey or accessToken, throwing only if neither is provided

Motivation

The proxy module currently only supports API key authentication (X-Goog-Api-Key), but the Stitch service layer already supports access tokens. This PR adds accessToken support to the proxy module to enable ADC/OAuth2 workflows, which is especially important for Windows users where system-level gcloud integration is needed and API keys may not be the preferred auth method.

Changes

  • spec/proxy.ts — Added accessToken and quotaProjectId to StitchProxyConfigSchema
  • proxy/core.ts — Constructor reads accessToken and quotaProjectId from config/env vars; validation guard accepts either credential
  • proxy/client.ts — New buildAuthHeaders() helper selects Authorization: Bearer + X-Goog-User-Project or X-Goog-Api-Key headers
  • test/proxy.test.ts — 4 new tests covering accessToken init, env var init, error on missing credentials, and header verification

Test plan

  • Verify proxy starts with STITCH_API_KEY set (existing behavior unchanged)
  • Verify proxy starts with STITCH_ACCESS_TOKEN set (new behavior)
  • Verify proxy throws if neither key nor token is provided
  • Verify Authorization: Bearer + X-Goog-User-Project headers sent with accessToken
  • Verify X-Goog-Api-Key header is sent when only apiKey is configured
  • Verified end-to-end: create_project tool call succeeds with Bearer + quota project

All 97 tests passing (14 test files).

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 14, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Eyalm321 pushed a commit to Eyalm321/stitch-mcp that referenced this pull request Apr 14, 2026
Wire gcloudService.getAccessToken() into the proxy handler so that when
STITCH_API_KEY is not set, the proxy falls back to Application Default
Credentials. This enables STITCH_USE_SYSTEM_GCLOUD workflows, especially
on Windows where system gcloud integration is needed.

Includes a patch-package patch for @google/stitch-sdk to add accessToken
support to the proxy module (schema, constructor, and HTTP headers).
The patch can be removed once google-labs-code/stitch-sdk#314 is merged
and released.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Eyalm321 Eyalm321 force-pushed the feat/access-token-auth branch 2 times, most recently from 9ab9e9f to 6fa48f3 Compare April 14, 2026 20:14
Eyalm321 added a commit to Eyalm321/stitch-mcp that referenced this pull request Apr 14, 2026
Wire gcloudService.getAccessToken() into the proxy handler so that when
STITCH_API_KEY is not set, the proxy falls back to Application Default
Credentials. This enables STITCH_USE_SYSTEM_GCLOUD workflows, especially
on Windows where system gcloud integration is needed.

Includes a patch-package patch for @google/stitch-sdk to add accessToken
support to the proxy module (schema, constructor, and HTTP headers).
The patch can be removed once google-labs-code/stitch-sdk#314 is merged
and released.
Eyalm321 added a commit to Eyalm321/stitch-mcp that referenced this pull request Apr 14, 2026
Wire gcloudService.getAccessToken() into the proxy handler so that when
STITCH_API_KEY is not set, the proxy falls back to Application Default
Credentials. This enables STITCH_USE_SYSTEM_GCLOUD workflows, especially
on Windows where system gcloud integration is needed.

Includes a patch-package patch for @google/stitch-sdk to add accessToken
support to the proxy module (schema, constructor, and HTTP headers).
The patch can be removed once google-labs-code/stitch-sdk#314 is merged
and released.
Eyalm321 added a commit to Eyalm321/stitch-mcp that referenced this pull request Apr 14, 2026
Wire gcloudService.getAccessToken() into the proxy handler so that when
STITCH_API_KEY is not set, the proxy falls back to Application Default
Credentials. This enables STITCH_USE_SYSTEM_GCLOUD workflows, especially
on Windows where system gcloud integration is needed.

Depends on google-labs-code/stitch-sdk#314 for accessToken support in
the SDK proxy module.
Eyalm321 added a commit to Eyalm321/stitch-mcp that referenced this pull request Apr 14, 2026
Wire gcloudService.getAccessToken() into the proxy handler so that when
STITCH_API_KEY is not set, the proxy falls back to Application Default
Credentials. This enables STITCH_USE_SYSTEM_GCLOUD workflows, especially
on Windows where system gcloud integration is needed.

Depends on google-labs-code/stitch-sdk#314 for accessToken support in
the SDK proxy module.
@Eyalm321 Eyalm321 force-pushed the feat/access-token-auth branch from 6fa48f3 to c9a04fe Compare April 14, 2026 20:31
Add accessToken and quotaProjectId as alternative authentication for the
proxy module, enabling ADC/OAuth2 workflows. When accessToken is provided
(via config or STITCH_ACCESS_TOKEN env var), the proxy sends
Authorization: Bearer and X-Goog-User-Project headers instead of
X-Goog-Api-Key.
@Eyalm321 Eyalm321 force-pushed the feat/access-token-auth branch from fd1423f to 8d90657 Compare April 14, 2026 20: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.

1 participant