- Add SSO QR status poller and assist platform HTTP client - Add assist-platform session store with 0600 secure permissions - Implement domains/assist-platform (api, services, types) for corporation search, detail, tickets, staff query and passwordless token generation - Implement cli/commands/assist-platform with aliases assist-center and ap - Support seamless --save --switch --elevate pipeline to import tenant and extract persistent OpenAPI credentials - Update embedded skill documentation, reference guide, and test suites
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
import ky, { type KyInstance } from "ky";
|
|
import { AuthenticationError } from "../errors.js";
|
|
|
|
export const DEFAULT_SSO_BASE_URL = "https://sso.hosecloud.com";
|
|
|
|
export interface SsoClientOptions {
|
|
baseUrl?: string;
|
|
timeout?: number;
|
|
}
|
|
|
|
export function createSsoClient(options: SsoClientOptions = {}): KyInstance {
|
|
const baseUrl = options.baseUrl || DEFAULT_SSO_BASE_URL;
|
|
return ky.create({
|
|
prefix: baseUrl,
|
|
timeout: options.timeout ?? 15000,
|
|
headers: {
|
|
accept: "application/json, text/plain, */*",
|
|
"user-agent": "hose-use/assist-platform-client",
|
|
referer: `${baseUrl}/`,
|
|
},
|
|
});
|
|
}
|
|
|
|
export interface QrCodeStatusResponse {
|
|
code: number;
|
|
message: string;
|
|
data?: {
|
|
token?: string;
|
|
ticket?: string;
|
|
redirectUrl?: string;
|
|
[key: string]: unknown;
|
|
} | string;
|
|
}
|
|
|
|
/**
|
|
* 轮询 HoseCloudSSO 钉钉扫码登录确认状态
|
|
*/
|
|
export async function pollSsoQrCodeStatus(
|
|
client: KyInstance,
|
|
options: {
|
|
sessionId?: string;
|
|
cookie?: string;
|
|
signal?: AbortSignal;
|
|
} = {}
|
|
): Promise<QrCodeStatusResponse> {
|
|
const headers: Record<string, string> = {};
|
|
if (options.cookie) {
|
|
headers.cookie = options.cookie;
|
|
} else if (options.sessionId) {
|
|
headers.cookie = `SSO_SESSION_ID=${options.sessionId}`;
|
|
}
|
|
|
|
try {
|
|
return await client
|
|
.get("api/v1/user/login/qrcode/status", {
|
|
searchParams: { _t: Date.now() },
|
|
headers,
|
|
signal: options.signal,
|
|
})
|
|
.json<QrCodeStatusResponse>();
|
|
} catch (error) {
|
|
if (error instanceof Error && error.name === "AbortError") {
|
|
throw error;
|
|
}
|
|
throw new AuthenticationError(
|
|
`SSO 状态轮询异常: ${error instanceof Error ? error.message : String(error)}`
|
|
);
|
|
}
|
|
}
|