feat(guild): validate bearer tokens via center introspection

This commit is contained in:
root
2026-05-13 07:59:57 +00:00
parent d9c5175233
commit b27cb0c2e1
6 changed files with 61 additions and 24 deletions

28
src/common/center-auth.ts Normal file
View File

@@ -0,0 +1,28 @@
export async function introspectGuildToken(token: string): Promise<{ active: boolean; user?: { id: string; email?: string } }> {
const centerBaseUrl = process.env.CENTER_BASE_URL;
const sharedSecret = process.env.CENTER_SHARED_SECRET;
const guildNodeId = process.env.GUILD_NODE_ID;
if (!centerBaseUrl || !sharedSecret || !guildNodeId) {
return { active: false };
}
const res = await fetch(`${centerBaseUrl}/api/auth/introspect`, {
method: 'POST',
headers: {
'content-type': 'application/json',
'x-center-shared-secret': sharedSecret,
},
body: JSON.stringify({ token, guildNodeId }),
});
if (!res.ok) return { active: false };
const data = (await res.json()) as { active?: boolean; user?: { id: string; email?: string } };
if (!data.active) return { active: false };
return {
active: true,
user: data.user,
};
}