From 0f8413c4413cf3fe2f97a4c64d507f28ec344145 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sun, 16 Aug 2026 10:09:43 -0700 Subject: [PATCH] Read OAuth 2.0 token responses from the send instead of the filesystem Both token requests opened HttpResponse.bodyPath with readFileSync, which ties the plugin to bodies living on a filesystem. The send now hands the body back, so they read it from there and keep working once bodies move into the blob DB and in the browser Worker, where there is no fs to read. text() on a response with no body returns "", which is what the bodyPath check produced, so an empty response still parses to {} rather than throwing. --- plugins/auth-oauth2/src/fetchAccessToken.ts | 6 +++--- plugins/auth-oauth2/src/getOrRefreshAccessToken.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/auth-oauth2/src/fetchAccessToken.ts b/plugins/auth-oauth2/src/fetchAccessToken.ts index 1f585b2a..8e682749 100644 --- a/plugins/auth-oauth2/src/fetchAccessToken.ts +++ b/plugins/auth-oauth2/src/fetchAccessToken.ts @@ -1,4 +1,3 @@ -import { readFileSync } from "node:fs"; import type { Context, HttpRequest, HttpUrlParameter } from "@yaakapp/api"; import type { AccessTokenRawResponse } from "./store"; @@ -57,7 +56,7 @@ export async function fetchAccessToken( } httpRequest.authenticationType = "none"; // Don't inherit workspace auth - const { httpResponse: resp } = await ctx.httpRequest.send({ httpRequest }); + const { httpResponse: resp, body: responseBody } = await ctx.httpRequest.send({ httpRequest }); console.log("[oauth2] Got access token response", resp.status); @@ -65,7 +64,8 @@ export async function fetchAccessToken( throw new Error(`Failed to fetch access token: ${resp.error}`); } - const body = resp.bodyPath ? readFileSync(resp.bodyPath, "utf8") : ""; + // Empty when the response had no body, which parses to {} below. + const body = await responseBody.text(); if (resp.status < 200 || resp.status >= 300) { throw new Error(`Failed to fetch access token with status=${resp.status} and body=${body}`); diff --git a/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts b/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts index 386a08ba..082b54c9 100644 --- a/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts +++ b/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts @@ -1,4 +1,3 @@ -import { readFileSync } from "node:fs"; import type { Context, HttpRequest } from "@yaakapp/api"; import type { AccessToken, AccessTokenRawResponse, TokenStoreArgs } from "./store"; import { deleteToken, getToken, storeToken } from "./store"; @@ -71,7 +70,7 @@ export async function getOrRefreshAccessToken( } httpRequest.authenticationType = "none"; // Don't inherit workspace auth - const { httpResponse: resp } = await ctx.httpRequest.send({ httpRequest }); + const { httpResponse: resp, body: responseBody } = await ctx.httpRequest.send({ httpRequest }); if (resp.error) { throw new Error(`Failed to refresh access token: ${resp.error}`); @@ -85,7 +84,8 @@ export async function getOrRefreshAccessToken( return null; } - const body = resp.bodyPath ? readFileSync(resp.bodyPath, "utf8") : ""; + // Empty when the response had no body, which parses to {} below. + const body = await responseBody.text(); console.log("[oauth2] Got refresh token response", resp.status);