Add auth hose-openapi-token command for Hose enterprises
This commit is contained in:
1 parent
7304578bc7
commit
6e4a8cb088
9 files changed
+301
-11
No files matched your search
@@ -1,7 +1,14 @@
|
||||
import { assertHoseAssistTenantMatches, exchangeHoseAssistLink, getHoseProvisionalAuthLink } from "../../core/auth/hose.js";
|
||||
import {
|
||||
assertHoseAssistTenantMatches,
|
||||
exchangeHoseAssistLink,
|
||||
getHoseOpenapiToken,
|
||||
getHoseProvisionalAuthLink,
|
||||
normalizeBaseUrl
|
||||
} from "../../core/auth/hose.js";
|
||||
import { clearCorpTokenCache } from "../../core/auth/token-store.js";
|
||||
import { formatBeijingIso } from "../../core/config/timestamps.js";
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
import { CliError, validationError } from "../../core/errors.js";
|
||||
import { createSealClient, createSealClientForUrl } from "../../core/http/factory.js";
|
||||
import { resolveSealCustomHeaders } from "../../core/http/request-headers.js";
|
||||
import { createDelegation, getMe } from "../../domains/seal/api.js";
|
||||
@@ -147,6 +154,44 @@ export async function handleAuthCommand(action: string | undefined, corp: CorpCo
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
action === "hose-openapi-token" ||
|
||||
action === "openapi-token" ||
|
||||
action === "hose-token"
|
||||
) {
|
||||
if (corp.source.type !== "hose") {
|
||||
throw new CliError(
|
||||
`【合思专享能力】当前企业「${corp.name}」(id: ${corp.id}) 为原生 Seal (${corp.source.type}) 租户,非合思 (Hose/合思云/易快报) 渠道企业。\n` +
|
||||
"OpenAPI accessToken 签发能力专属于合思生态租户(使用持久化的 appKey/appSecurity 向合思 OpenAPI 换取 token),非合思渠道企业不支持此命令。",
|
||||
2
|
||||
);
|
||||
}
|
||||
const appKey = corp.source.appKey ?? corp.source.key;
|
||||
const appSecurity = corp.source.appSecurity ?? corp.source.password;
|
||||
if (!appKey || !appSecurity) {
|
||||
throw validationError(
|
||||
`缺少合思凭证:企业「${corp.name}」(id: ${corp.id}) 未配置 appKey/appSecurity(或 key/password),无法向合思 OpenAPI 签发 accessToken。`
|
||||
);
|
||||
}
|
||||
const force =
|
||||
booleanOption(args.options.force) === true ||
|
||||
booleanOption(args.options.refresh) === true ||
|
||||
booleanOption(args.options.f) === true;
|
||||
const entry = await getHoseOpenapiToken(corp, { force });
|
||||
if (entry.cached) {
|
||||
console.error("ℹ️ [合思 OpenAPI] 复用本地仍有效的 accessToken 缓存,追加 --force 可强制签发全新 token。");
|
||||
}
|
||||
printJson({
|
||||
corpId: corp.source.corpId ?? corp.id,
|
||||
corpName: corp.name,
|
||||
domain: normalizeBaseUrl(corp.source.domain),
|
||||
token: entry.token,
|
||||
expiresAt: formatBeijingIso(entry.expiresAt),
|
||||
cached: entry.cached
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "keys" || action === "hose-keys") {
|
||||
const reveal =
|
||||
booleanOption(args.options.reveal) === true ||
|
||||
|
||||
Reference in new issue
Block a user