fix: stabilize auth identity, record operations, and workflow diagnostics
This commit is contained in:
1 parent
c74fdda7da
commit
7ec369f77e
36 files changed
+1021
-337
No files matched your search
@@ -424,6 +424,10 @@ export async function getCorpProvisionalAuthLink(
|
||||
const targetStaffId = options.staffId || corp.staffId || corp.credentials.staffId;
|
||||
const targetStaffName = options.staffName || (options.staffId ? undefined : corp.staffName || corp.session?.staffName);
|
||||
const baseUrl = normalizeBaseUrl(corp.baseUrl || DEFAULT_EKB_BASE_URL);
|
||||
const syncLocalSession = options.syncLocalSession !== false && (!options.staffId || options.persistStaff === true);
|
||||
if (options.staffId && !hasOpenApiPersistentCredentials(corp)) {
|
||||
throw new AuthenticationError("切换员工签发链接需要已配置的 OpenAPI 持久化密钥,现有会话不能代表其他员工。");
|
||||
}
|
||||
|
||||
// 1. 若尚未配置 appKey/appSecurity,先确保会话有效并尝试自动提权提取密钥
|
||||
if (!hasOpenApiPersistentCredentials(corp)) {
|
||||
@@ -455,21 +459,26 @@ export async function getCorpProvisionalAuthLink(
|
||||
pageType,
|
||||
});
|
||||
|
||||
if (options.syncLocalSession !== false) {
|
||||
corp.credentials.accessToken = provisional.token;
|
||||
if (!corp.auth) corp.auth = { refreshTtl: 300 };
|
||||
corp.auth.expiresAt = provisional.expiresAt;
|
||||
if (corp.session) {
|
||||
corp.session.expTime = provisional.expiresAt;
|
||||
const normalizedStaffId = targetStaffId.includes(":") ? targetStaffId : `${corpId}:${targetStaffId}`;
|
||||
if (provisional.uid !== normalizedStaffId) {
|
||||
throw new AuthenticationError("免密链接签发身份与目标员工不一致,未更新本地会话。");
|
||||
}
|
||||
if (syncLocalSession) {
|
||||
const updated = structuredClone(corp);
|
||||
updated.credentials.accessToken = provisional.token;
|
||||
if (!updated.auth) updated.auth = { refreshTtl: 300 };
|
||||
updated.auth.expiresAt = provisional.expiresAt;
|
||||
if (updated.session) {
|
||||
updated.session.expTime = provisional.expiresAt;
|
||||
}
|
||||
if (options.persistStaff && options.staffId) {
|
||||
corp.staffId = options.staffId;
|
||||
corp.credentials.staffId = options.staffId;
|
||||
if (options.staffName) {
|
||||
corp.staffName = options.staffName;
|
||||
}
|
||||
updated.staffId = normalizedStaffId;
|
||||
updated.credentials.staffId = normalizedStaffId;
|
||||
updated.staffName = options.staffName;
|
||||
if (updated.session) updated.session.staffName = options.staffName;
|
||||
}
|
||||
saveCorpConfig(corp, options.enterprisesDir);
|
||||
saveCorpConfig(updated, options.enterprisesDir);
|
||||
Object.assign(corp, updated);
|
||||
invalidateCorpSubdomainTokenCaches(corp);
|
||||
}
|
||||
|
||||
@@ -477,7 +486,7 @@ export async function getCorpProvisionalAuthLink(
|
||||
corpId,
|
||||
corpName: corp.name,
|
||||
staffId: provisional.uid || targetStaffId,
|
||||
staffName: targetStaffName || corp.staffName || corp.session?.staffName || undefined,
|
||||
staffName: targetStaffName ?? undefined,
|
||||
url: provisional.url,
|
||||
token: provisional.token,
|
||||
expiresIn: provisional.expiresIn,
|
||||
@@ -504,7 +513,7 @@ export async function getCorpProvisionalAuthLink(
|
||||
);
|
||||
}
|
||||
|
||||
if (explicitDuration !== undefined && options.syncLocalSession !== false) {
|
||||
if (explicitDuration !== undefined && syncLocalSession) {
|
||||
if (!corp.auth) corp.auth = { refreshTtl: 300 };
|
||||
corp.auth.expiresAt = expMs;
|
||||
if (corp.session) {
|
||||
|
||||
Reference in new issue
Block a user