文件
hyb-oa/client/src/api/auth.ts
T

63 行
1.8 KiB
TypeScript

import { apiRequestData } from "./http";
import { getDeviceFingerprint } from "../auth/deviceFingerprint";
import type { LoginResponse } from "./types";
const JSON_HEADERS = {
"content-type": "application/json",
};
export async function changePassword(payload: { oldPassword: string; newPassword: string }) {
return apiRequestData<LoginResponse>("/api/auth/change-password", {
method: "POST",
headers: {
...JSON_HEADERS,
"x-device-fingerprint": getDeviceFingerprint(),
},
body: JSON.stringify(payload),
});
}
export type SsoProviderInfo = { id: "oidc"; label: string; enabled: boolean; loginUrl: string };
export type WecomEntryConfig = {
enabled: boolean;
entryEnabled: boolean;
oauthEnabled: boolean;
corpId: string;
agentId: string;
loginUrl: string | null;
bindEnabled: boolean;
defaultReturnTo: string;
status: "ready" | "disabled" | "misconfigured";
statusReasons: string[];
};
export async function fetchSsoProviders() {
return apiRequestData<SsoProviderInfo[]>("/api/auth/sso/providers", { auth: false });
}
export async function fetchWecomConfig() {
return apiRequestData<WecomEntryConfig>("/api/auth/wecom/config", { auth: false });
}
export async function startWecomBind(returnTo = "/settings/profile") {
return apiRequestData<{ loginUrl: string }>("/api/auth/wecom/bind", {
method: "POST",
body: JSON.stringify({ returnTo }),
});
}
export async function unbindWecom() {
return apiRequestData<{ ok: boolean }>("/api/auth/wecom/unbind", {
method: "POST",
body: JSON.stringify({}),
});
}
export async function updateNotificationPreferences(payload: { notificationPushEnabled: boolean }) {
return apiRequestData<{ notificationPushEnabled: boolean }>("/api/me/notification-preferences", {
method: "PATCH",
body: JSON.stringify(payload),
});
}