discordOAuth.ts
@file The Discord half of Linked Roles: authorize URL, the two OAuth2…
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>
Who an access token belongs to — never a username, only the ID, matching every other identity this bot stores.
handleDiscordCallbackFexport async function pushRoleConnection(accessToken: string, applicationId: string, metadata: Record<string, string>, correlationId: string): Promise<boolean>
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.
pushMetadataNowUndocumented (3)
discordAuthorizeUrl, tokenRequest, exchangeDiscordCode