Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(google): show Google's real 401/403 instead of "Could not determine client ID" (#16314)

James Novino7231623d22af
diff --git a/brain/knowledge/connections-auth/app-connections.md b/brain/knowledge/connections-auth/app-connections.md
index 910e37386e2..f05a164716d 100644
--- a/brain/knowledge/connections-auth/app-connections.md
+++ b/brain/knowledge/connections-auth/app-connections.md
@@ -29,6 +29,7 @@ Encrypted credential records (OAuth2 tokens, API keys, basic/custom auth, OIDC p
- `metadata.accountIdentifier` (the "which account is this" label) must be **rewritten on every upsert, never left untouched** — `spreadIfDefined` omits the column and TypeORM `upsert(connection, ['id'])` then leaves the old value in place, so a reconnect that fails to resolve would keep labelling the connection with an account it no longer authenticates as. `mergeConnectionMetadata` also strips the key from caller-supplied `metadata`, because `metadata` is a caller-owned jsonb bag: without that, any `WRITE_APP_CONNECTION` holder can forge the label. Note `POST /:id` (update) still replaces the whole bag.
- **A pasted service-account JSON is attacker-controlled config, and `token_uri` inside it is an SSRF vector.** A Google service-account key file carries its own `token_uri`/`auth_uri`, and `google-auth-library` (`GoogleAuth`, `JWT`) *honours* them — so `{ ...JSON.parse(raw) }` handed to `googleAuthOptions.credentials` lets whoever pasted the file redirect the OAuth token exchange to any host, link-local metadata included, behind a valid-looking `type: service_account`. Forward only the fields you use (`client_email`, `private_key`, `project_id` if you check it); never spread the parsed object. This bit the Vertex AI provider in review, and **`packages/pieces/community/google-vertexai/.../common.ts` still does `{ ...raw, private_key }`** — worse there than in a provider, because a piece connection needs only connection-write, not platform admin. The same `new GoogleAuth`/`new JWT` shape recurs across the google-* pieces, so grep before assuming one is narrow. Note `.claude/rules/safe-http.md` does **not** catch this: the request is made inside the auth library, never through `safeHttp.axios`, so the rule's "admin config reaching outbound HTTP" clause has to be applied by hand.
+- **Never hand a Google `OAuth2Client` the whole OAuth2 connection value. Pass `setCredentials({ access_token })` only.** The client is built with no client ID or secret (`setCredentials` ignores any `client_id` in the value), but the value carries a `refresh_token` and no `expiry_date`. In `google-auth-library` 10.x that keeps the retry-on-401/403 path open: the library tries its own refresh, sends only `{refresh_token, grant_type}`, and Google's `400 invalid_request` "Could not determine client ID from request." replaces the real 401/403. This hits every OAuth2 flavour, and the library refresh gains nothing, because the server refreshes 15 minutes before expiry (`oauth2Util.isExpired`). Every Google piece's `createGoogleClient` follows this, and each has `test/oauth2-client.test.ts` asserting it; a new Google piece should copy that test. #11529 fixed only Slides, and #15648 put the bug back, which is why each piece now has the test. Upstream report: #16268.
- **The two live OAuth2 redirect pages disagree on percent-decoding, so `getCode` decodes conditionally. Do not collapse it back to an unconditional decode, in either direction.** `redirect.tsx` decodes once via `URLSearchParams`, while **`https://secrets.activepieces.com/redirect` - the page every `CLOUD_OAUTH2` connect uses, and which does not live in this repo - posts the code raw, zero decodes** (verified 2026-09-08: `?code=k1%2Fk2` posts `'k1%2Fk2'`). `getCode` decodes only when `oauth2Type === AppConnectionType.CLOUD_OAUTH2` - the same condition `oauth2Utils.resolveRedirectUrl` uses to pick the secrets page - falling back to the raw value if `decodeURIComponent` throws. **The two live in separate files and nothing ties them together, so a third redirect page must be added to both**: pick its URL in `resolveRedirectUrl` and state its decode contract in `getCode`, or the pair drifts and you are back at this bug. The Mustache page in `app.ts` is a third sender on paper only: `setupApp` mounts under the `/api` prefix, so it serves at **`/api/redirect`**, nothing in the repo points at it, and a bare `/redirect` always falls through to the SPA. Deleting the decode outright was tried in #14879 and reverted 21 hours later in #14926, because it broke every managed OAuth app, self-hosted as much as Cloud: `CLOUD_OAUTH2` means "managed app", not "on Cloud", and `platform.cloudAuthEnabled` defaults to true everywhere. It also fired much more readily than the bug it fixed, since a raw posted code breaks on any `/`, `+` or `=` while the double decode needs a literal `%`. Grepping this repo for the senders is not enough; the cloud one is invisible here - and neither are tests, by themselves: #14879 shipped three of them, CI does run web tests (`ci.yml`, `--filter=web`), and they passed, because all three modelled `redirect.tsx`'s contract only. `oauth2-authorization-code-decode.test.ts` now covers both contracts, and fails in both directions. See decision *The browser normalises OAuth2 authorization codes, because the cloud redirect contract is frozen*.
### Key files
diff --git a/bun.lock b/bun.lock
index 8f2b130f8d2..5da09cc7e19 100644
--- a/bun.lock
+++ b/bun.lock
@@ -3858,6 +3858,7 @@
},
"devDependencies": {
"tslib": "2.6.2",
+ "vitest": "3.2.6",
},
},
"packages/pieces/community/google-docs": {
@@ -3912,6 +3913,7 @@
},
"devDependencies": {
"tslib": "2.6.2",
+ "vitest": "3.2.6",
},
},
"packages/pieces/community/google-gemini": {
@@ -3998,6 +4000,7 @@
},
"devDependencies": {
"tslib": "2.6.2",
+ "vitest": "3.2.6",
},
},
"packages/pieces/community/google-slides": {
diff --git a/packages/pieces/community/gmail/package.json b/packages/pieces/community/gmail/package.json
index fc380203344..c4b493ff966 100644
--- a/packages/pieces/community/gmail/package.json
+++ b/packages/pieces/community/gmail/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-gmail",
- "version": "0.17.4",
+ "version": "0.17.5",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
diff --git a/packages/pieces/community/gmail/src/lib/auth.ts b/packages/pieces/community/gmail/src/lib/auth.ts
index 911ba1c6b83..77d44c89ff8 100644
--- a/packages/pieces/community/gmail/src/lib/auth.ts
+++ b/packages/pieces/community/gmail/src/lib/auth.ts
@@ -98,7 +98,7 @@ export async function createGoogleClient(
});
}
const authClient = new OAuth2Client();
- authClient.setCredentials(auth);
+ authClient.setCredentials({ access_token: auth.access_token });
return authClient;
}
diff --git a/packages/pieces/community/gmail/test/oauth2-client.test.ts b/packages/pieces/community/gmail/test/oauth2-client.test.ts
new file mode 100644
index 00000000000..6a2820d90cf
--- /dev/null
+++ b/packages/pieces/community/gmail/test/oauth2-client.test.ts
@@ -0,0 +1,69 @@
+import { AppConnectionType } from '@activepieces/pieces-framework';
+import { describe, expect, test } from 'vitest';
+import { createGoogleClient } from '../src/lib/auth';
+
+describe('createGoogleClient with an OAuth2 connection', () => {
+ test('gives the client only the access token', async () => {
+ const client = await createGoogleClient(connection);
+
+ expect(client.credentials).toEqual({ access_token: ACCESS_TOKEN });
+ });
+
+ test('surfaces a rejected access token as the 401 Google returned, without a token refresh', async () => {
+ const client = await createGoogleClient(connection);
+ const requestedUrls: string[] = [];
+ client.transporter.defaults.fetchImplementation = async (input) => {
+ const url = input instanceof Request ? input.url : String(input);
+ requestedUrls.push(url);
+ return url === TOKEN_URL
+ ? jsonResponse({
+ status: 400,
+ body: {
+ error: 'invalid_request',
+ error_description: 'Could not determine client ID from request.',
+ },
+ })
+ : jsonResponse({
+ status: 401,
+ body: { error: { code: 401, status: 'UNAUTHENTICATED' } },
+ });
+ };
+
+ await expect(client.request({ url: API_URL })).rejects.toMatchObject({
+ status: 401,
+ });
+ expect(requestedUrls).toEqual([API_URL]);
+ });
+});
+
+function jsonResponse({
+ status,
+ body,
+}: {
+ status: number;
+ body: unknown;
+}): Response {
+ return new Response(JSON.stringify(body), {
+ status,
+ headers: { 'content-type': 'application/json' },
+ });
+}
+
+const ACCESS_TOKEN = 'access-token';
+const API_URL = 'https://gmail.googleapis.com/gmail/v1/users/me/profile';
+const TOKEN_URL = 'https://oauth2.googleapis.com/token';
+
+const connection: Parameters<typeof createGoogleClient>[0] = {
+ type: AppConnectionType.OAUTH2,
+ access_token: ACCESS_TOKEN,
+ refresh_token: 'refresh-token',
+ client_id: 'client-id',
+ client_secret: 'client-secret',
+ redirect_url: 'https://example.com/redirect',
+ token_type: 'Bearer',
+ token_url: TOKEN_URL,
+ scope: 'email',
+ claimed_at: Math.round(Date.now() / 1000),
+ expires_in: 3600,
+ data: {},
+};
diff --git a/packages/pieces/community/google-calendar/package.json b/packages/pieces/community/google-calendar/package.json
index fe844da8ba5..591daf5755d 100644
--- a/packages/pieces/community/google-calendar/package.json
+++ b/packages/pieces/community/google-calendar/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-google-calendar",
- "version": "0.12.2",
+ "version": "0.12.3",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
diff --git a/packages/pieces/community/google-calendar/src/lib/auth.ts b/packages/pieces/community/google-calendar/src/lib/auth.ts
index 4b2a3a4fbf5..57aa5a7f8d6 100644
--- a/packages/pieces/community/google-calendar/src/lib/auth.ts
+++ b/packages/pieces/community/google-calendar/src/lib/auth.ts
@@ -64,7 +64,7 @@ export async function createGoogleClient(auth: GoogleCalendarAuthValue): Promise
});
}
const authClient = new OAuth2Client();
- authClient.setCredentials(auth);
+ authClient.setCredentials({ access_token: auth.access_token });
return authClient;
}
diff --git a/packages/pieces/community/google-calendar/test/oauth2-client.test.ts b/packages/pieces/community/google-calendar/test/oauth2-client.test.ts
new file mode 100644
index 00000000000..b9eecb0de3d
--- /dev/null
+++ b/packages/pieces/community/google-calendar/test/oauth2-client.test.ts
@@ -0,0 +1,69 @@
+import { AppConnectionType } from '@activepieces/pieces-framework';
+import { describe, expect, test } from 'vitest';
+import { createGoogleClient } from '../src/lib/auth';
+
+describe('createGoogleClient with an OAuth2 connection', () => {
+ test('gives the client only the access token', async () => {
+ const client = await createGoogleClient(connection);
+
+ expect(client.credentials).toEqual({ access_token: ACCESS_TOKEN });
+ });
+
+ test('surfaces a rejected access token as the 401 Google returned, without a token refresh', async () => {
+ const client = await createGoogleClient(connection);
+ const requestedUrls: string[] = [];
+ client.transporter.defaults.fetchImplementation = async (input) => {
+ const url = input instanceof Request ? input.url : String(input);
+ requestedUrls.push(url);
+ return url === TOKEN_URL
+ ? jsonResponse({
+ status: 400,
+ body: {
+ error: 'invalid_request',
+ error_description: 'Could not determine client ID from request.',
+ },
+ })
+ : jsonResponse({
+ status: 401,
+ body: { error: { code: 401, status: 'UNAUTHENTICATED' } },
+ });
+ };
+
+ await expect(client.request({ url: API_URL })).rejects.toMatchObject({
+ status: 401,
+ });
+ expect(requestedUrls).toEqual([API_URL]);
+ });
+});
+
+function jsonResponse({
+ status,
+ body,
+}: {
+ status: number;
+ body: unknown;
+}): Response {
+ return new Response(JSON.stringify(body), {
+ status,
+ headers: { 'content-type': 'application/json' },
+ });
+}
+
+const ACCESS_TOKEN = 'access-token';
+const API_URL = 'https://www.googleapis.com/calendar/v3/users/me/calendarList';
+const TOKEN_URL = 'https://oauth2.googleapis.com/token';
+
+const connection: Parameters<typeof createGoogleClient>[0] = {
+ type: AppConnectionType.OAUTH2,
+ access_token: ACCESS_TOKEN,
+ refresh_token: 'refresh-token',
+ client_id: 'client-id',
+ client_secret: 'client-secret',
+ redirect_url: 'https://example.com/redirect',
+ token_type: 'Bearer',
+ token_url: TOKEN_URL,
+ scope: 'email',
+ claimed_at: Math.round(Date.now() / 1000),
+ expires_in: 3600,
+ data: {},
+};
diff --git a/packages/pieces/community/google-contacts/package.json b/packages/pieces/community/google-contacts/package.json
index 7f3c4221f7a..2db30fb5975 100644
--- a/packages/pieces/community/google-contacts/package.json
+++ b/packages/pieces/community/google-contacts/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-google-contacts",
- "version": "0.5.3",
+ "version": "0.5.4",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
@@ -13,11 +13,13 @@
"@activepieces/core-utils": "workspace:*"
},
"devDependencies": {
- "tslib": "2.6.2"
+ "tslib": "2.6.2",
+ "vitest": "3.2.6"
},
"scripts": {
"build": "tsc -p tsconfig.lib.json && cp package.json dist/",
"bundle": "node ../../../../dist/packages/cli/src/index.js pieces bundle",
- "lint": "eslint 'src/**/*.ts'"
+ "lint": "eslint 'src/**/*.ts'",
+ "test": "vitest run"
}
}
diff --git a/packages/pieces/community/google-contacts/src/lib/auth.ts b/packages/pieces/community/google-contacts/src/lib/auth.ts
index f0c5bcd8e49..ce41717a058 100644
--- a/packages/pieces/community/google-contacts/src/lib/auth.ts
+++ b/packages/pieces/community/google-contacts/src/lib/auth.ts
@@ -1,4 +1,5 @@
-import { PieceAuth } from '@activepieces/pieces-framework';
+import { AppConnectionValueForAuthProperty, PieceAuth } from '@activepieces/pieces-framework';
+import { OAuth2Client } from 'google-auth-library';
export const googleContactsAuth = PieceAuth.OAuth2({
description: '',
@@ -8,3 +9,11 @@ export const googleContactsAuth = PieceAuth.OAuth2({
required: true,
scope: ['https://www.googleapis.com/auth/contacts', 'email'],
});
+
+export function createGoogleClient(auth: GoogleContactsAuthValue): OAuth2Client {
+ const authClient = new OAuth2Client();
+ authClient.setCredentials({ access_token: auth.access_token });
+ return authClient;
+}
+
+export type GoogleContactsAuthValue = AppConnectionValueForAuthProperty<typeof googleContactsAuth>;
diff --git a/packages/pieces/community/google-contacts/src/lib/trigger/new-contact.ts b/packages/pieces/community/google-contacts/src/lib/trigger/new-contact.ts
index 15d5c071a01..03c314adbc5 100644
--- a/packages/pieces/community/google-contacts/src/lib/trigger/new-contact.ts
+++ b/packages/pieces/community/google-contacts/src/lib/trigger/new-contact.ts
@@ -9,19 +9,15 @@ import {
DedupeStrategy,
pollingHelper,
} from '@activepieces/pieces-common';
-import { googleContactsAuth } from '../auth';
+import { createGoogleClient, googleContactsAuth } from '../auth';
import { newOrUpdatedContactOutputSchema } from '../output-schemas';
import { people as googlePeople } from '@googleapis/people';
-import { OAuth2Client } from 'google-auth-library';
import dayjs from 'dayjs';
const polling: Polling<AppConnectionValueForAuthProperty<typeof googleContactsAuth>, Record<string, never>> = {
strategy: DedupeStrategy.TIMEBASED,
items: async ({ store, auth }) => {
- const authClient = new OAuth2Client();
- authClient.setCredentials(auth);
-
- const contactsClient = googlePeople({ version: 'v1', auth: authClient });
+ const contactsClient = googlePeople({ version: 'v1', auth: createGoogleClient(auth) });
let nextPageToken;
const contactItems: Array<{ data: any; epochMilliSeconds: number }> = [];
diff --git a/packages/pieces/community/google-contacts/test/oauth2-client.test.ts b/packages/pieces/community/google-contacts/test/oauth2-client.test.ts
new file mode 100644
index 00000000000..ba9e98eef29
--- /dev/null
+++ b/packages/pieces/community/google-contacts/test/oauth2-client.test.ts
@@ -0,0 +1,69 @@
+import { AppConnectionType } from '@activepieces/pieces-framework';
+import { describe, expect, test } from 'vitest';
+import { createGoogleClient } from '../src/lib/auth';
+
+describe('createGoogleClient with an OAuth2 connection', () => {
+ test('gives the client only the access token', async () => {
+ const client = await createGoogleClient(connection);
+
+ expect(client.credentials).toEqual({ access_token: ACCESS_TOKEN });
+ });
+
+ test('surfaces a rejected access token as the 401 Google returned, without a token refresh', async () => {
+ const client = await createGoogleClient(connection);
+ const requestedUrls: string[] = [];
+ client.transporter.defaults.fetchImplementation = async (input) => {
+ const url = input instanceof Request ? input.url : String(input);
+ requestedUrls.push(url);
+ return url === TOKEN_URL
+ ? jsonResponse({
+ status: 400,
+ body: {
+ error: 'invalid_request',
+ error_description: 'Could not determine client ID from request.',
+ },
+ })
+ : jsonResponse({
+ status: 401,
+ body: { error: { code: 401, status: 'UNAUTHENTICATED' } },
+ });
+ };
+
+ await expect(client.request({ url: API_URL })).rejects.toMatchObject({
+ status: 401,
+ });
+ expect(requestedUrls).toEqual([API_URL]);
+ });
+});
+
+function jsonResponse({
+ status,
+ body,
+}: {
+ status: number;
+ body: unknown;
+}): Response {
+ return new Response(JSON.stringify(body), {
+ status,
+ headers: { 'content-type': 'application/json' },
+ });
+}
+
+const ACCESS_TOKEN = 'access-token';
+const API_URL = 'https://people.googleapis.com/v1/people/me/connections';
+const TOKEN_URL = 'https://oauth2.googleapis.com/token';
+
+const connection: Parameters<typeof createGoogleClient>[0] = {
+ type: AppConnectionType.OAUTH2,
+ access_token: ACCESS_TOKEN,
+ refresh_token: 'refresh-token',
+ client_id: 'client-id',
+ client_secret: 'client-secret',
+ redirect_url: 'https://example.com/redirect',
+ token_type: 'Bearer',
+ token_url: TOKEN_URL,
+ scope: 'email',
+ claimed_at: Math.round(Date.now() / 1000),
+ expires_in: 3600,
+ data: {},
+};
diff --git a/packages/pieces/community/google-contacts/vitest.config.ts b/packages/pieces/community/google-contacts/vitest.config.ts
new file mode 100644
index 00000000000..ba8ade4a178
--- /dev/null
+++ b/packages/pieces/community/google-contacts/vitest.config.ts
@@ -0,0 +1,17 @@
+import path from 'path'
+import { defineConfig } from 'vitest/config'
+
+const repoRoot = path.resolve(__dirname, '../../../..')
+
+export default defineConfig({
+ test: {
+ globals: true,
+ environment: 'node',
+ },
+ resolve: {
+ alias: {
+ '@activepieces/pieces-framework': path.resolve(repoRoot, 'packages/pieces/framework/src/index.ts'),
+ '@activepieces/pieces-common': path.resolve(repoRoot, 'packages/pieces/common/src/index.ts'),
+ },
+ },
+})
diff --git a/packages/pieces/community/google-docs/package.json b/packages/pieces/community/google-docs/package.json
index a5ce013155a..dd1b853e395 100644
--- a/packages/pieces/community/google-docs/package.json
+++ b/packages/pieces/community/google-docs/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-google-docs",
- "version": "0.5.3",
+ "version": "0.5.4",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
diff --git a/packages/pieces/community/google-docs/src/lib/auth.ts b/packages/pieces/community/google-docs/src/lib/auth.ts
index 2ec030bd651..cb3f98a3c2b 100644
--- a/packages/pieces/community/google-docs/src/lib/auth.ts
+++ b/packages/pieces/community/google-docs/src/lib/auth.ts
@@ -73,7 +73,7 @@ export async function createGoogleClient(auth: GoogleDocsAuthValue): Promise<OAu
});
}
const authClient = new OAuth2Client();
- authClient.setCredentials(auth);
+ authClient.setCredentials({ access_token: auth.access_token });
return authClient;
}
diff --git a/packages/pieces/community/google-docs/test/oauth2-client.test.ts b/packages/pieces/community/google-docs/test/oauth2-client.test.ts
new file mode 100644
index 00000000000..173ae9b9fb5
--- /dev/null
+++ b/packages/pieces/community/google-docs/test/oauth2-client.test.ts
@@ -0,0 +1,69 @@
+import { AppConnectionType } from '@activepieces/pieces-framework';
+import { describe, expect, test } from 'vitest';
+import { createGoogleClient } from '../src/lib/auth';
+
+describe('createGoogleClient with an OAuth2 connection', () => {
+ test('gives the client only the access token', async () => {
+ const client = await createGoogleClient(connection);
+
+ expect(client.credentials).toEqual({ access_token: ACCESS_TOKEN });
+ });
+
+ test('surfaces a rejected access token as the 401 Google returned, without a token refresh', async () => {
+ const client = await createGoogleClient(connection);
+ const requestedUrls: string[] = [];
+ client.transporter.defaults.fetchImplementation = async (input) => {
+ const url = input instanceof Request ? input.url : String(input);
+ requestedUrls.push(url);
+ return url === TOKEN_URL
+ ? jsonResponse({
+ status: 400,
+ body: {
+ error: 'invalid_request',
+ error_description: 'Could not determine client ID from request.',
+ },
+ })
+ : jsonResponse({
+ status: 401,
+ body: { error: { code: 401, status: 'UNAUTHENTICATED' } },
+ });
+ };
+
+ await expect(client.request({ url: API_URL })).rejects.toMatchObject({
+ status: 401,
+ });
+ expect(requestedUrls).toEqual([API_URL]);
+ });
+});
+
+function jsonResponse({
+ status,
+ body,
+}: {
+ status: number;
+ body: unknown;
+}): Response {
+ return new Response(JSON.stringify(body), {
+ status,
+ headers: { 'content-type': 'application/json' },
+ });
+}
+
+const ACCESS_TOKEN = 'access-token';
+const API_URL = 'https://docs.googleapis.com/v1/documents/document-id';
+const TOKEN_URL = 'https://oauth2.googleapis.com/token';
+
+const connection: Parameters<typeof createGoogleClient>[0] = {
+ type: AppConnectionType.OAUTH2,
+ access_token: ACCESS_TOKEN,
+ refresh_token: 'refresh-token',
+ client_id: 'client-id',
+ client_secret: 'client-secret',
+ redirect_url: 'https://example.com/redirect',
+ token_type: 'Bearer',
+ token_url: TOKEN_URL,
+ scope: 'email',
+ claimed_at: Math.round(Date.now() / 1000),
+ expires_in: 3600,
+ data: {},
+};
diff --git a/packages/pieces/community/google-drive/package.json b/packages/pieces/community/google-drive/package.json
index ee17bbec874..ec33b387ace 100644
--- a/packages/pieces/community/google-drive/package.json
+++ b/packages/pieces/community/google-drive/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-google-drive",
- "version": "0.11.2",
+ "version": "0.11.3",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
diff --git a/packages/pieces/community/google-drive/src/lib/auth.ts b/packages/pieces/community/google-drive/src/lib/auth.ts
index 80a3020eea6..c0774e7756d 100644
--- a/packages/pieces/community/google-drive/src/lib/auth.ts
+++ b/packages/pieces/community/google-drive/src/lib/auth.ts
@@ -61,7 +61,7 @@ export async function createGoogleClient(auth: GoogleDriveAuthValue): Promise<OA
});
}
const authClient = new OAuth2Client();
- authClient.setCredentials(auth);
+ authClient.setCredentials({ access_token: auth.access_token });
return authClient;
}
diff --git a/packages/pieces/community/google-drive/test/oauth2-client.test.ts b/packages/pieces/community/google-drive/test/oauth2-client.test.ts
new file mode 100644
index 00000000000..d5fa2bfcb98
--- /dev/null
+++ b/packages/pieces/community/google-drive/test/oauth2-client.test.ts
@@ -0,0 +1,69 @@
+import { AppConnectionType } from '@activepieces/pieces-framework';
+import { describe, expect, test } from 'vitest';
+import { createGoogleClient } from '../src/lib/auth';
+
+describe('createGoogleClient with an OAuth2 connection', () => {
+ test('gives the client only the access token', async () => {
+ const client = await createGoogleClient(connection);
+
+ expect(client.credentials).toEqual({ access_token: ACCESS_TOKEN });
+ });
+
+ test('surfaces a rejected access token as the 401 Google returned, without a token refresh', async () => {
+ const client = await createGoogleClient(connection);
+ const requestedUrls: string[] = [];
+ client.transporter.defaults.fetchImplementation = async (input) => {
+ const url = input instanceof Request ? input.url : String(input);
+ requestedUrls.push(url);
+ return url === TOKEN_URL
+ ? jsonResponse({
+ status: 400,
+ body: {
+ error: 'invalid_request',
+ error_description: 'Could not determine client ID from request.',
+ },
+ })
+ : jsonResponse({
+ status: 401,
+ body: { error: { code: 401, status: 'UNAUTHENTICATED' } },
+ });
+ };
+
+ await expect(client.request({ url: API_URL })).rejects.toMatchObject({
+ status: 401,
+ });
+ expect(requestedUrls).toEqual([API_URL]);
+ });
+});
+
+function jsonResponse({
+ status,
+ body,
+}: {
+ status: number;
+ body: unknown;
+}): Response {
+ return new Response(JSON.stringify(body), {
+ status,
+ headers: { 'content-type': 'application/json' },
+ });
+}
+
+const ACCESS_TOKEN = 'access-token';
+const API_URL = 'https://www.googleapis.com/drive/v3/files';
+const TOKEN_URL = 'https://oauth2.googleapis.com/token';
+
+const connection: Parameters<typeof createGoogleClient>[0] = {
+ type: AppConnectionType.OAUTH2,
+ access_token: ACCESS_TOKEN,
+ refresh_token: 'refresh-token',
+ client_id: 'client-id',
+ client_secret: 'client-secret',
+ redirect_url: 'https://example.com/redirect',
+ token_type: 'Bearer',
+ token_url: TOKEN_URL,
+ scope: 'email',
+ claimed_at: Math.round(Date.now() / 1000),
+ expires_in: 3600,
+ data: {},
+};
diff --git a/packages/pieces/community/google-forms/package.json b/packages/pieces/community/google-forms/package.json
index 4d754e7679d..40eb7fc3d2f 100644
--- a/packages/pieces/community/google-forms/package.json
+++ b/packages/pieces/community/google-forms/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-google-forms",
- "version": "0.7.1",
+ "version": "0.7.2",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
@@ -12,11 +12,13 @@
"@activepieces/core-utils": "workspace:*"
},
"devDependencies": {
- "tslib": "2.6.2"
+ "tslib": "2.6.2",
+ "vitest": "3.2.6"
},
"scripts": {
"build": "tsc -p tsconfig.lib.json && cp package.json dist/",
"bundle": "node ../../../../dist/packages/cli/src/index.js pieces bundle",
- "lint": "eslint 'src/**/*.ts'"
+ "lint": "eslint 'src/**/*.ts'",
+ "test": "vitest run"
}
}
diff --git a/packages/pieces/community/google-forms/src/lib/common/common.ts b/packages/pieces/community/google-forms/src/lib/common/common.ts
index c4e04f290b0..07a76433012 100644
--- a/packages/pieces/community/google-forms/src/lib/common/common.ts
+++ b/packages/pieces/community/google-forms/src/lib/common/common.ts
@@ -72,7 +72,7 @@ export async function createGoogleClient(auth: GoogleFormsAuthValue): Promise<OA
});
}
const authClient = new OAuth2Client();
- authClient.setCredentials(auth);
+ authClient.setCredentials({ access_token: auth.access_token });
return authClient;
}
diff --git a/packages/pieces/community/google-forms/test/oauth2-client.test.ts b/packages/pieces/community/google-forms/test/oauth2-client.test.ts
new file mode 100644
index 00000000000..af4fcd15990
--- /dev/null
+++ b/packages/pieces/community/google-forms/test/oauth2-client.test.ts
@@ -0,0 +1,69 @@
+import { AppConnectionType } from '@activepieces/pieces-framework';
+import { describe, expect, test } from 'vitest';
+import { createGoogleClient } from '../src/lib/common/common';
+
+describe('createGoogleClient with an OAuth2 connection', () => {
+ test('gives the client only the access token', async () => {
+ const client = await createGoogleClient(connection);
+
+ expect(client.credentials).toEqual({ access_token: ACCESS_TOKEN });
+ });
+
+ test('surfaces a rejected access token as the 401 Google returned, without a token refresh', async () => {
+ const client = await createGoogleClient(connection);
+ const requestedUrls: string[] = [];
+ client.transporter.defaults.fetchImplementation = async (input) => {
+ const url = input instanceof Request ? input.url : String(input);
+ requestedUrls.push(url);
+ return url === TOKEN_URL
+ ? jsonResponse({
+ status: 400,
+ body: {
+ error: 'invalid_request',
+ error_description: 'Could not determine client ID from request.',
+ },
+ })
+ : jsonResponse({
+ status: 401,
+ body: { error: { code: 401, status: 'UNAUTHENTICATED' } },
+ });
+ };
+
+ await expect(client.request({ url: API_URL })).rejects.toMatchObject({
+ status: 401,
+ });
+ expect(requestedUrls).toEqual([API_URL]);
+ });
+});
+
+function jsonResponse({
+ status,
+ body,
+}: {
+ status: number;
+ body: unknown;
+}): Response {
+ return new Response(JSON.stringify(body), {
+ status,
+ headers: { 'content-type': 'application/json' },
+ });
+}
+
+const ACCESS_TOKEN = 'access-token';
+const API_URL = 'https://forms.googleapis.com/v1/forms/form-id';
+const TOKEN_URL = 'https://oauth2.googleapis.com/token';
+
+const connection: Parameters<typeof createGoogleClient>[0] = {
+ type: AppConnectionType.OAUTH2,
+ access_token: ACCESS_TOKEN,
+ refresh_token: 'refresh-token',
+ client_id: 'client-id',
+ client_secret: 'client-secret',
+ redirect_url: 'https://example.com/redirect',
+ token_type: 'Bearer',
+ token_url: TOKEN_URL,
+ scope: 'email',
+ claimed_at: Math.round(Date.now() / 1000),
+ expires_in: 3600,
+ data: {},
+};
diff --git a/packages/pieces/community/google-forms/vitest.config.ts b/packages/pieces/community/google-forms/vitest.config.ts
new file mode 100644
index 00000000000..ba8ade4a178
--- /dev/null
+++ b/packages/pieces/community/google-forms/vitest.config.ts
@@ -0,0 +1,17 @@
+import path from 'path'
+import { defineConfig } from 'vitest/config'
+
+const repoRoot = path.resolve(__dirname, '../../../..')
+
+export default defineConfig({
+ test: {
+ globals: true,
+ environment: 'node',
+ },
+ resolve: {
+ alias: {
+ '@activepieces/pieces-framework': path.resolve(repoRoot, 'packages/pieces/framework/src/index.ts'),
+ '@activepieces/pieces-common': path.resolve(repoRoot, 'packages/pieces/common/src/index.ts'),
+ },
+ },
+})
diff --git a/packages/pieces/community/google-sheets/package.json b/packages/pieces/community/google-sheets/package.json
index 0426ad41687..8fd8f459058 100644
--- a/packages/pieces/community/google-sheets/package.json
+++ b/packages/pieces/community/google-sheets/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-google-sheets",
- "version": "0.17.1",
+ "version": "0.17.2",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
@@ -19,11 +19,13 @@
"@activepieces/core-utils": "workspace:*"
},
"devDependencies": {
- "tslib": "2.6.2"
+ "tslib": "2.6.2",
+ "vitest": "3.2.6"
},
"scripts": {
"build": "tsc -p tsconfig.lib.json && cp package.json dist/",
"bundle": "node ../../../../dist/packages/cli/src/index.js pieces bundle",
- "lint": "eslint 'src/**/*.ts'"
+ "lint": "eslint 'src/**/*.ts'",
+ "test": "vitest run"
}
}
diff --git a/packages/pieces/community/google-sheets/src/lib/common/common.ts b/packages/pieces/community/google-sheets/src/lib/common/common.ts
index c72088d524c..1f5ef7bc270 100644
--- a/packages/pieces/community/google-sheets/src/lib/common/common.ts
+++ b/packages/pieces/community/google-sheets/src/lib/common/common.ts
@@ -311,7 +311,7 @@ export async function createGoogleClient(auth: GoogleSheetsAuthValue): Promise<O
});
}
const authClient = new OAuth2Client();
- authClient.setCredentials(auth);
+ authClient.setCredentials({ access_token: auth.access_token });
return authClient;
}
diff --git a/packages/pieces/community/google-sheets/test/oauth2-client.test.ts b/packages/pieces/community/google-sheets/test/oauth2-client.test.ts
new file mode 100644
index 00000000000..e1a57047eba
--- /dev/null
+++ b/packages/pieces/community/google-sheets/test/oauth2-client.test.ts
@@ -0,0 +1,69 @@
+import { AppConnectionType } from '@activepieces/pieces-framework';
+import { describe, expect, test } from 'vitest';
+import { createGoogleClient } from '../src/lib/common/common';
+
+describe('createGoogleClient with an OAuth2 connection', () => {
+ test('gives the client only the access token', async () => {
+ const client = await createGoogleClient(connection);
+
+ expect(client.credentials).toEqual({ access_token: ACCESS_TOKEN });
+ });
+
+ test('surfaces a rejected access token as the 401 Google returned, without a token refresh', async () => {
+ const client = await createGoogleClient(connection);
+ const requestedUrls: string[] = [];
+ client.transporter.defaults.fetchImplementation = async (input) => {
+ const url = input instanceof Request ? input.url : String(input);
+ requestedUrls.push(url);
+ return url === TOKEN_URL
+ ? jsonResponse({
+ status: 400,
+ body: {
+ error: 'invalid_request',
+ error_description: 'Could not determine client ID from request.',
+ },
+ })
+ : jsonResponse({
+ status: 401,
+ body: { error: { code: 401, status: 'UNAUTHENTICATED' } },
+ });
+ };
+
+ await expect(client.request({ url: API_URL })).rejects.toMatchObject({
+ status: 401,
+ });
+ expect(requestedUrls).toEqual([API_URL]);
+ });
+});
+
+function jsonResponse({
+ status,
+ body,
+}: {
+ status: number;
+ body: unknown;
+}): Response {
+ return new Response(JSON.stringify(body), {
+ status,
+ headers: { 'content-type': 'application/json' },
+ });
+}
+
+const ACCESS_TOKEN = 'access-token';
+const API_URL = 'https://sheets.googleapis.com/v4/spreadsheets/spreadsheet-id';
+const TOKEN_URL = 'https://oauth2.googleapis.com/token';
+
+const connection: Parameters<typeof createGoogleClient>[0] = {
+ type: AppConnectionType.OAUTH2,
+ access_token: ACCESS_TOKEN,
+ refresh_token: 'refresh-token',
+ client_id: 'client-id',
+ client_secret: 'client-secret',
+ redirect_url: 'https://example.com/redirect',
+ token_type: 'Bearer',
+ token_url: TOKEN_URL,
+ scope: 'email',
+ claimed_at: Math.round(Date.now() / 1000),
+ expires_in: 3600,
+ data: {},
+};
diff --git a/packages/pieces/community/google-sheets/vitest.config.ts b/packages/pieces/community/google-sheets/vitest.config.ts
new file mode 100644
index 00000000000..ba8ade4a178
--- /dev/null
+++ b/packages/pieces/community/google-sheets/vitest.config.ts
@@ -0,0 +1,17 @@
+import path from 'path'
+import { defineConfig } from 'vitest/config'
+
+const repoRoot = path.resolve(__dirname, '../../../..')
+
+export default defineConfig({
+ test: {
+ globals: true,
+ environment: 'node',
+ },
+ resolve: {
+ alias: {
+ '@activepieces/pieces-framework': path.resolve(repoRoot, 'packages/pieces/framework/src/index.ts'),
+ '@activepieces/pieces-common': path.resolve(repoRoot, 'packages/pieces/common/src/index.ts'),
+ },
+ },
+})
diff --git a/packages/pieces/community/google-slides/package.json b/packages/pieces/community/google-slides/package.json
index ebf7191df20..b9c36d7802a 100644
--- a/packages/pieces/community/google-slides/package.json
+++ b/packages/pieces/community/google-slides/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-google-slides",
- "version": "0.4.1",
+ "version": "0.4.2",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
diff --git a/packages/pieces/community/google-slides/src/lib/auth.ts b/packages/pieces/community/google-slides/src/lib/auth.ts
index fa2ce646748..825861a6f61 100644
--- a/packages/pieces/community/google-slides/src/lib/auth.ts
+++ b/packages/pieces/community/google-slides/src/lib/auth.ts
@@ -78,7 +78,7 @@ export async function createGoogleClient(
});
}
const authClient = new OAuth2Client();
- authClient.setCredentials(auth);
+ authClient.setCredentials({ access_token: auth.access_token });
return authClient;
}
diff --git a/packages/pieces/community/google-slides/test/oauth2-client.test.ts b/packages/pieces/community/google-slides/test/oauth2-client.test.ts
new file mode 100644
index 00000000000..62292668a13
--- /dev/null
+++ b/packages/pieces/community/google-slides/test/oauth2-client.test.ts
@@ -0,0 +1,69 @@
+import { AppConnectionType } from '@activepieces/pieces-framework';
+import { describe, expect, test } from 'vitest';
+import { createGoogleClient } from '../src/lib/auth';
+
+describe('createGoogleClient with an OAuth2 connection', () => {
+ test('gives the client only the access token', async () => {
+ const client = await createGoogleClient(connection);
+
+ expect(client.credentials).toEqual({ access_token: ACCESS_TOKEN });
+ });
+
+ test('surfaces a rejected access token as the 401 Google returned, without a token refresh', async () => {
+ const client = await createGoogleClient(connection);
+ const requestedUrls: string[] = [];
+ client.transporter.defaults.fetchImplementation = async (input) => {
+ const url = input instanceof Request ? input.url : String(input);
+ requestedUrls.push(url);
+ return url === TOKEN_URL
+ ? jsonResponse({
+ status: 400,
+ body: {
+ error: 'invalid_request',
+ error_description: 'Could not determine client ID from request.',
+ },
+ })
+ : jsonResponse({
+ status: 401,
+ body: { error: { code: 401, status: 'UNAUTHENTICATED' } },
+ });
+ };
+
+ await expect(client.request({ url: API_URL })).rejects.toMatchObject({
+ status: 401,
+ });
+ expect(requestedUrls).toEqual([API_URL]);
+ });
+});
+
+function jsonResponse({
+ status,
+ body,
+}: {
+ status: number;
+ body: unknown;
+}): Response {
+ return new Response(JSON.stringify(body), {
+ status,
+ headers: { 'content-type': 'application/json' },
+ });
+}
+
+const ACCESS_TOKEN = 'access-token';
+const API_URL = 'https://slides.googleapis.com/v1/presentations/presentation-id';
+const TOKEN_URL = 'https://oauth2.googleapis.com/token';
+
+const connection: Parameters<typeof createGoogleClient>[0] = {
+ type: AppConnectionType.OAUTH2,
+ access_token: ACCESS_TOKEN,
+ refresh_token: 'refresh-token',
+ client_id: 'client-id',
+ client_secret: 'client-secret',
+ redirect_url: 'https://example.com/redirect',
+ token_type: 'Bearer',
+ token_url: TOKEN_URL,
+ scope: 'email',
+ claimed_at: Math.round(Date.now() / 1000),
+ expires_in: 3600,
+ data: {},
+};