bot/src/discordOAuth.ts
openaliro/openaliro
Module

discordOAuth.ts

@file The Discord half of Linked Roles: authorize URL, the two OAuth2…

bot/src/discordOAuth.ts2 documented symbols

Overview

@file The Discord half of Linked Roles: authorize URL, the two OAuth2 token-endpoint grants (authorization_code, refresh_token), identifying who authorized, and pushing the final role-connection metadata. Every endpoint and body shape here was checked against docs.discord.com (2026-08-04) rather than assumed — this is a different trust boundary from the rest of the bot (a real bearer credential granted by an actual user, not just their opaque Discord ID), so it is worth being sure. identify is requested alongside role_connections.write: the metadata push endpoint is scoped to "whoever this access token belongs to", so the callback needs GET /users/@me to learn *which* Discord user just authorized before it can store anything against them.

used by linkedRoles.ts

API

Fexport async function getDiscordUserId(accessToken: string, correlationId: string): Promise<string | null>

bot/src/discordOAuth.ts:96

Who an access token belongs to — never a username, only the ID, matching every other identity this bot stores.

called by handleDiscordCallback

Fexport async function pushRoleConnection(accessToken: string, applicationId: string, metadata: Record<string, string>, correlationId: string): Promise<boolean>

bot/src/discordOAuth.ts:115

The final step: hands Discord the stringified metadata for whoever accessToken belongs to. Uses the user's own bearer token, not the bot token — this is a user-scoped endpoint by design.

called by pushMetadataNow
Undocumented (3)

discordAuthorizeUrl, tokenRequest, exchangeDiscordCode