mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-04 22:01:15 +00:00
refactor: add approval auth capabilities to more channels
This commit is contained in:
24
extensions/feishu/src/approval-auth.test.ts
Normal file
24
extensions/feishu/src/approval-auth.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { feishuApprovalAuth } from "./approval-auth.js";
|
||||
|
||||
describe("feishuApprovalAuth", () => {
|
||||
it("authorizes open_id approvers and ignores user_id-only allowlists", () => {
|
||||
expect(
|
||||
feishuApprovalAuth.authorizeActorAction({
|
||||
cfg: { channels: { feishu: { allowFrom: ["ou_owner"] } } },
|
||||
senderId: "ou_owner",
|
||||
action: "approve",
|
||||
approvalKind: "exec",
|
||||
}),
|
||||
).toEqual({ authorized: true });
|
||||
|
||||
expect(
|
||||
feishuApprovalAuth.authorizeActorAction({
|
||||
cfg: { channels: { feishu: { allowFrom: ["user_123"] } } },
|
||||
senderId: "ou_attacker",
|
||||
action: "approve",
|
||||
approvalKind: "exec",
|
||||
}),
|
||||
).toEqual({ authorized: true });
|
||||
});
|
||||
});
|
||||
24
extensions/feishu/src/approval-auth.ts
Normal file
24
extensions/feishu/src/approval-auth.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
createResolvedApproverActionAuthAdapter,
|
||||
resolveApprovalApprovers,
|
||||
} from "openclaw/plugin-sdk/approval-runtime";
|
||||
import { resolveFeishuAccount } from "./accounts.js";
|
||||
import { normalizeFeishuTarget } from "./targets.js";
|
||||
|
||||
function normalizeFeishuApproverId(value: string | number): string | undefined {
|
||||
const normalized = normalizeFeishuTarget(String(value));
|
||||
const trimmed = normalized?.trim().toLowerCase();
|
||||
return trimmed?.startsWith("ou_") ? trimmed : undefined;
|
||||
}
|
||||
|
||||
export const feishuApprovalAuth = createResolvedApproverActionAuthAdapter({
|
||||
channelLabel: "Feishu",
|
||||
resolveApprovers: ({ cfg, accountId }) => {
|
||||
const account = resolveFeishuAccount({ cfg, accountId }).config;
|
||||
return resolveApprovalApprovers({
|
||||
allowFrom: account.allowFrom,
|
||||
normalizeApprover: normalizeFeishuApproverId,
|
||||
});
|
||||
},
|
||||
normalizeSenderId: (value) => normalizeFeishuApproverId(value),
|
||||
});
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
listEnabledFeishuAccounts,
|
||||
resolveDefaultFeishuAccountId,
|
||||
} from "./accounts.js";
|
||||
import { feishuApprovalAuth } from "./approval-auth.js";
|
||||
import { FEISHU_CARD_INTERACTION_VERSION } from "./card-interaction.js";
|
||||
import { createFeishuClient } from "./client.js";
|
||||
import { FeishuConfigSchema } from "./config-schema.js";
|
||||
@@ -612,6 +613,7 @@ export const feishuPlugin: ChannelPlugin<ResolvedFeishuAccount, FeishuProbeResul
|
||||
},
|
||||
}),
|
||||
},
|
||||
auth: feishuApprovalAuth,
|
||||
actions: {
|
||||
describeMessageTool: describeFeishuMessageTool,
|
||||
handleAction: async (ctx) => {
|
||||
|
||||
Reference in New Issue
Block a user