mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-23 16:54:12 +01:00
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:
1 parent
7d0926c961
commit
7a6d275fdb
16 files changed
+771
-5
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import type { Context, HttpRequest } from "@yaakapp/api";
|
||||
import type { CustomRequestParams } from "./customParams";
|
||||
import { mergeFormParams, mergeHeaders } from "./customParams";
|
||||
import type { AccessToken, AccessTokenRawResponse, TokenStoreArgs } from "./store";
|
||||
import { deleteToken, getToken, storeToken } from "./store";
|
||||
import { isTokenExpired } from "./util";
|
||||
@@ -14,6 +16,7 @@ export async function getOrRefreshAccessToken(
|
||||
clientSecret,
|
||||
tokenName,
|
||||
forceRefresh,
|
||||
custom,
|
||||
}: {
|
||||
scope: string | null;
|
||||
accessTokenUrl: string;
|
||||
@@ -22,6 +25,7 @@ export async function getOrRefreshAccessToken(
|
||||
clientSecret: string;
|
||||
tokenName?: "access_token" | "id_token";
|
||||
forceRefresh?: boolean;
|
||||
custom?: CustomRequestParams;
|
||||
},
|
||||
): Promise<AccessToken | null> {
|
||||
const token = await getToken(ctx, tokenArgs);
|
||||
@@ -69,6 +73,12 @@ export async function getOrRefreshAccessToken(
|
||||
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 });
|
||||
|
||||
|
||||
Reference in new issue
Block a user