{"_id":"@aethex.os/discord","_rev":"3-90a6cac64736b63998f3bce05054e107","name":"@aethex.os/discord","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@aethex.os/discord","version":"1.0.0","keywords":["discord","oauth","discord-activity","discord-login","auth","social-login","aethex"],"author":{"name":"AeThex Corporation"},"license":"MIT","_id":"@aethex.os/discord@1.0.0","maintainers":[{"name":"mrpiglr","email":"mrpiglr@aethex.dev"}],"homepage":"https://aethex.dev","bugs":{"url":"https://github.com/AeThex-Corporation/AeThex-OS/issues"},"dist":{"shasum":"889cf26e6bb8a24e2d2dbc86acfda9d042ae6da9","tarball":"https://registry.npmjs.org/@aethex.os/discord/-/discord-1.0.0.tgz","fileCount":14,"integrity":"sha512-dAz9eSE5EghUSB5lPDDoISqUNMbfWuZaHSu3LV8DvlgRz6JtiEJkH7DT21k4pjE0KdyZYoCXjDZtFK7NlwVlew==","signatures":[{"sig":"MEUCIC92y+EXdSYE86iy/XAkXP9a9N55UwzW06cJh850RTPcAiEAzx4EZLbuqG5ANU0K/G7L+qVv/YfsmJY+9yzt/6q/kqM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19517},"main":"lib/index.js","types":"lib/index.d.ts","engines":{"node":">=18.0.0"},"gitHead":"b094d5c032765a30612c2348ce0356d3a50d9feb","scripts":{"dev":"tsc --watch","build":"tsc"},"_npmUser":{"name":"mrpiglr","email":"mrpiglr@aethex.dev"},"repository":{"url":"git+https://github.com/AeThex-Corporation/AeThex-OS.git","type":"git","directory":"packages/aethex-discord"},"_npmVersion":"11.12.1","description":"Discord OAuth and Activity auth helpers — build Discord login, account linking, and Discord Activity authentication in minutes","directories":{},"_nodeVersion":"22.22.0","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.3.0","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/discord_1.0.0_1777933719538_0.7913947407708419","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@aethex.os/discord","version":"1.0.1","keywords":["discord","oauth","discord-activity","discord-login","auth","social-login","aethex"],"author":{"name":"AeThex Corporation"},"license":"MIT","_id":"@aethex.os/discord@1.0.1","maintainers":[{"name":"mrpiglr","email":"mrpiglr@aethex.dev"}],"homepage":"https://aethex.dev","bugs":{"url":"https://github.com/AeThex-Corporation/AeThex-OS/issues"},"dist":{"shasum":"20ed1560f8d40938bd96948a8af2d2fdacf18405","tarball":"https://registry.npmjs.org/@aethex.os/discord/-/discord-1.0.1.tgz","fileCount":14,"integrity":"sha512-WIwPfBox62tH3UNkUFDciUVcvfHSZtEuZwtlGzUYLGzGfMdOmEkcfD7157mAioJJIWAEY1Mr5vT4bU/weJmVvQ==","signatures":[{"sig":"MEYCIQCZD0sm5yHdr+G+7H7cbCcCQ7YaCHcBjOVmDhV1GJ7hpwIhAJVDHOJxQBwk8wx3FJ9Q95kukLdBXsvjwJMyZJvx9sF6","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19518},"main":"lib/index.js","types":"lib/index.d.ts","engines":{"node":">=18.0.0"},"gitHead":"b094d5c032765a30612c2348ce0356d3a50d9feb","scripts":{"dev":"tsc --watch","build":"tsc"},"_npmUser":{"name":"mrpiglr","email":"mrpiglr@aethex.dev"},"repository":{"url":"git+https://github.com/AeThex-Corporation/AeThex-OS.git","type":"git","directory":"packages/aethex-discord"},"_npmVersion":"11.12.1","description":"Discord OAuth and Activity auth helpers — build Discord login, account linking, and Discord Activity authentication in minutes","directories":{},"_nodeVersion":"22.22.0","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.3.0","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/discord_1.0.1_1777933777200_0.2964697425507745","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@aethex.os/discord","version":"1.0.2","description":"Discord OAuth and Activity auth helpers — build Discord login, account linking, and Discord Activity authentication in minutes","main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc","dev":"tsc --watch"},"keywords":["discord","oauth","discord-activity","discord-login","auth","social-login","aethex"],"author":{"name":"AeThex Corporation"},"license":"MIT","homepage":"https://aethex.dev/docs","repository":{"type":"git","url":"git+https://git.aethex.tech/Labs/os.git","directory":"packages/aethex-discord"},"devDependencies":{"@types/node":"^20.0.0","typescript":"^5.3.0"},"engines":{"node":">=18.0.0"},"bugs":{"url":"https://git.aethex.tech/Labs/os/issues"},"_id":"@aethex.os/discord@1.0.2","gitHead":"6c77abd6440deb925777f64998d4c67a398236e0","_nodeVersion":"22.22.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-QdBubF4Tszwp9BtR92KblcC/Hk4MQop9CGyJRaExi7BHwIqW3rKhNzbou4IqC7EUhJfGJSkeEBBPBZbawexpUQ==","shasum":"ab438e8830a5ad20e9dd0aa705028310141505c7","tarball":"https://registry.npmjs.org/@aethex.os/discord/-/discord-1.0.2.tgz","fileCount":14,"unpackedSize":19580,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIFDpf1RomIHlmddU+nflAXkmmwRvyERuVTC02ie5mgP3AiBBNtCksnHV+s3cXDYqEA8ASBvzyRnoSkhlRIWXGzJnOw=="}]},"_npmUser":{"name":"mrpiglr","email":"mrpiglr@aethex.dev"},"directories":{},"maintainers":[{"name":"mrpiglr","email":"mrpiglr@aethex.dev"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/discord_1.0.2_1783400201795_0.832794920754794"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-04T22:28:39.483Z","modified":"2026-07-07T04:56:42.089Z","1.0.0":"2026-05-04T22:28:39.689Z","1.0.1":"2026-05-04T22:29:37.353Z","1.0.2":"2026-07-07T04:56:41.950Z"},"bugs":{"url":"https://git.aethex.tech/Labs/os/issues"},"author":{"name":"AeThex Corporation"},"license":"MIT","homepage":"https://aethex.dev/docs","keywords":["discord","oauth","discord-activity","discord-login","auth","social-login","aethex"],"repository":{"type":"git","url":"git+https://git.aethex.tech/Labs/os.git","directory":"packages/aethex-discord"},"description":"Discord OAuth and Activity auth helpers — build Discord login, account linking, and Discord Activity authentication in minutes","maintainers":[{"name":"mrpiglr","email":"mrpiglr@aethex.dev"}],"readme":"# @aethex.os/discord\n\nDiscord OAuth and Activity auth helpers — build Discord login, account linking, and Discord Activity authentication in minutes.\n\n## Install\n\n```bash\nnpm install @aethex.os/discord\n```\n\nNo extra dependencies. Uses the native `fetch` API (Node 18+).\n\n## OAuth login flow\n\n```ts\nimport { buildOAuthUrl, exchangeCode, getDiscordUser, getAvatarUrl } from \"@aethex.os/discord\";\n\nconst config = {\n  clientId: process.env.DISCORD_CLIENT_ID!,\n  clientSecret: process.env.DISCORD_CLIENT_SECRET!,\n  redirectUri: \"https://myapp.com/api/discord/callback\",\n};\n\n// 1. Redirect user to Discord\napp.get(\"/api/discord/login\", (req, res) => {\n  const url = buildOAuthUrl(config, { action: \"login\", redirectTo: \"/dashboard\" });\n  res.redirect(url);\n});\n\n// 2. Handle callback\napp.get(\"/api/discord/callback\", async (req, res) => {\n  const { code, state } = req.query;\n  const tokens = await exchangeCode(code as string, config);\n  const user = await getDiscordUser(tokens.accessToken);\n\n  console.log(user.id, user.username, user.email);\n  console.log(getAvatarUrl(user)); // https://cdn.discordapp.com/avatars/...\n\n  // create session, store tokens, redirect\n  res.redirect(\"/dashboard\");\n});\n```\n\n## Account linking\n\n```ts\nimport { buildOAuthUrl, parseState } from \"@aethex.os/discord\";\n\n// Generate a linking URL with a session token in state\nconst url = buildOAuthUrl(config, {\n  action: \"link\",\n  sessionToken: crypto.randomUUID(),\n  redirectTo: \"/settings\",\n});\n\n// In the callback, parse state to detect link vs login\nconst stateData = parseState(req.query.state as string);\nif (stateData.action === \"link\") {\n  // retrieve sessionToken from your DB to get the authenticated userId\n}\n```\n\n## Discord Activity auth\n\nVerify a Discord Activity SDK `access_token` server-side:\n\n```ts\nimport { verifyActivityToken } from \"@aethex.os/discord\";\n\napp.post(\"/api/activity/auth\", async (req, res) => {\n  const { access_token } = req.body;\n  const user = await verifyActivityToken(access_token);\n  // user.id, user.username, user.avatarUrl\n  res.json({ user });\n});\n```\n\nOr use the built-in Express handler:\n\n```ts\nimport { createActivityAuthHandler } from \"@aethex.os/discord\";\n\napp.post(\n  \"/api/activity/auth\",\n  createActivityAuthHandler({\n    onUserVerified: async (user) => {\n      // upsert user in your database\n      await db.users.upsert({ discordId: user.id, username: user.username });\n    },\n  })\n);\n```\n\n## Token refresh\n\n```ts\nimport { refreshTokens } from \"@aethex.os/discord\";\n\nconst newTokens = await refreshTokens(storedRefreshToken, {\n  clientId: process.env.DISCORD_CLIENT_ID!,\n  clientSecret: process.env.DISCORD_CLIENT_SECRET!,\n});\n```\n\n## API\n\n| Function | Description |\n|----------|-------------|\n| `buildOAuthUrl(config, state?)` | Build the Discord OAuth authorization URL |\n| `exchangeCode(code, config)` | Exchange an authorization code for tokens |\n| `getDiscordUser(accessToken)` | Fetch the authenticated Discord user |\n| `getAvatarUrl(user, format?)` | Get a user's avatar CDN URL |\n| `refreshTokens(refreshToken, config)` | Refresh an expired access token |\n| `parseState(stateParam)` | Parse the state query parameter |\n| `verifyActivityToken(accessToken)` | Verify a Discord Activity access token |\n| `createActivityAuthHandler(config?)` | Express handler for Activity auth |\n\n---\n\nPart of the [`@aethex.os`](https://www.npmjs.com/search?q=%40aethex.os) toolkit.\n","readmeFilename":"README.md"}