fix(msteams): improve graph user and token parsing

This commit is contained in:
Peter Steinberger
2026-02-22 11:28:19 +00:00
parent e80c66a571
commit 8c1afc4b63
9 changed files with 145 additions and 85 deletions

View File

@@ -1,8 +1,5 @@
import { searchGraphUsers } from "./graph-users.js";
import {
escapeOData,
fetchGraphJson,
type GraphResponse,
type GraphUser,
listChannelsForTeam,
listTeamsByName,
normalizeQuery,
@@ -182,22 +179,7 @@ export async function resolveMSTeamsUserAllowlist(params: {
results.push({ input, resolved: true, id: query });
continue;
}
let users: GraphUser[] = [];
if (query.includes("@")) {
const escaped = escapeOData(query);
const filter = `(mail eq '${escaped}' or userPrincipalName eq '${escaped}')`;
const path = `/users?$filter=${encodeURIComponent(filter)}&$select=id,displayName,mail,userPrincipalName`;
const res = await fetchGraphJson<GraphResponse<GraphUser>>({ token, path });
users = res.value ?? [];
} else {
const path = `/users?$search=${encodeURIComponent(`"displayName:${query}"`)}&$select=id,displayName,mail,userPrincipalName&$top=10`;
const res = await fetchGraphJson<GraphResponse<GraphUser>>({
token,
path,
headers: { ConsistencyLevel: "eventual" },
});
users = res.value ?? [];
}
const users = await searchGraphUsers({ token, query, top: 10 });
const match = users[0];
if (!match?.id) {
results.push({ input, resolved: false });