feat: add seal auth providers

This commit is contained in:
gitea committed 2026-06-05 16:04:09 +08:00
1 parent 25e4dd7714
commit d575683c8b
8 files changed
+510

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
import ky, { HTTPError, KyInstance } from "ky";
import { CorpConfig } from "../config/types.js";
import { clearSealToken, getSealSessionForCorp } from "../auth/seal.js";
export async function createSealClient(corp: CorpConfig): Promise<KyInstance> {
const session = await getSealSessionForCorp(corp);
return ky.create({
prefix: session.enterprise.sealUrl,
timeout: 30000,
headers: {
Authorization: `Bearer ${session.token}`
},
hooks: {
beforeError: [
async ({ error }) => {
if (error instanceof HTTPError && error.response.status === 401) {
clearSealToken(corp.id);
}
const body =
error instanceof HTTPError
? await error.response.text().catch(() => "")
: "";
error.message = `${error.message}${body ? `: ${body}` : ""}`;
return error;
}
]
}
});
}