feat(auth-oauth2): custom parameters for authorization, token, and refresh requests (#629)

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Gregory SchierandClaude Opus 5 authored and GitHub committed 2026-09-13 09:15:25 -07:00
1 parent 7d0926c961
commit 7a6d275fdb
16 files changed
+771 -5

No files matched your search

+10 -1
View File
@@ -1,4 +1,6 @@
import type { Context, HttpRequest, HttpUrlParameter } from "@yaakapp/api";
import type { CustomRequestParams } from "./customParams";
import { mergeFormParams, mergeHeaders } from "./customParams";
import type { AccessTokenRawResponse } from "./store";
export async function fetchAccessToken(
@@ -10,9 +12,10 @@ export async function fetchAccessToken(
scope: string | null;
audience: string | null;
params: HttpUrlParameter[];
custom?: CustomRequestParams;
} & ({ clientAssertion: string } | { clientSecret: string; credentialsInBody: boolean }),
): Promise<AccessTokenRawResponse> {
const { clientId, grantType, accessTokenUrl, scope, audience, params } = args;
const { clientId, grantType, accessTokenUrl, scope, audience, params, custom } = args;
console.log("[oauth2] Getting access token", accessTokenUrl);
const httpRequest: Partial<HttpRequest> = {
method: "POST",
@@ -61,6 +64,12 @@ export async function fetchAccessToken(
httpRequest.headers?.push({ name: "Authorization", value });
}
// Merged last so custom entries override the credential headers and params above
if (custom) {
httpRequest.headers = mergeHeaders(httpRequest.headers ?? [], custom.headers);
httpRequest.body = { form: mergeFormParams(httpRequest.body?.form ?? [], custom.body) };
}
httpRequest.authenticationType = "none"; // Don't inherit workspace auth
const { httpResponse: resp, body: responseBody } = await ctx.httpRequest.send({ httpRequest });