oauth-provider
Add a new OAuth/OIDC identity provider to MUDdown. Covers the shared type, auth switch statements, server config, login page button, env vars, tests, and local verification.
- License 许可
- MIT
- 所属仓库
- MUDdown/MUDdown
- 最近更新
- 2026-08-06
- Stars
- ★ 2
- Forks
- 2
01 前言 Front Matter
- name
- oauth-provider
- description
- Add a new OAuth/OIDC identity provider to MUDdown. Covers the shared type, auth switch statements, server config, login page button, env vars, tests, and local verification.
03 SKILL.md 正文
OAuth Provider Skill
You are adding a new OAuth or OIDC identity provider to MUDdown. This is a multi-file change that touches shared types, server auth logic, server startup config, the login page, env files, and tests.
Files to Modify (in order)
1. packages/shared/src/index.ts — Register the provider
Add the new provider string to the OAUTH_PROVIDERS tuple so it is included in the shared provider type and validation guard. This tuple does not control the login-button display order; update apps/website/src/pages/login.astro separately if you need to change the UI order.
export const OAUTH_PROVIDERS = ["discord", "github", "microsoft", "google"] as const;
The OAuthProvider type and isOAuthProvider() guard derive from this array automatically — no other changes needed in shared.
2. packages/server/src/auth.ts — Implement the three protocol functions
Add a case for the new provider in all three switch statements. Each uses assertNever(provider) as the default, so the build will fail if any switch is missed.
| Function | Purpose | Key details |
|---|---|---|
buildAuthorizeUrl() |
Construct the OAuth authorize redirect URL | Set scope, response_type, client_id, redirect_uri, state |
exchangeCodeForToken() |
Exchange the authorization code for an access token | Know whether the provider expects JSON or application/x-www-form-urlencoded |
fetchProviderUser() |
Fetch the authenticated user's profile | Map provider fields to { providerId, username, displayName } |
Common pitfalls:
- Discord's token endpoint requires
Content-Type: application/x-www-form-urlencodedwith aURLSearchParamsbody (not JSON). - Some providers return the user ID as a number (GitHub), others as a string (Discord snowflake). Always convert to
String(). - The
displayNamefield should use the provider's "friendly name" field (e.g., Discordglobal_name, GitHubname, MicrosoftdisplayName).
3. packages/server/src/index.ts — Wire up provider config
Add a buildProviderConfig() call for the new provider's env vars, following the existing pattern:
const exampleCfg = buildProviderConfig("EXAMPLE_CLIENT_ID", "EXAMPLE_CLIENT_SECRET", "EXAMPLE_CALLBACK_URL");
if (exampleCfg) oauthConfig.example = exampleCfg;
Also add a callback-URL warning in the if (exampleCfg && !process.env.EXAMPLE_CALLBACK_URL) block.
4. apps/website/src/pages/login.astro — Add the login button
Add a new <button> in the provider list with the provider's brand SVG icon. Register it in the providerButtons record in the <script> block. The /auth/providers endpoint controls provider availability; providers not returned are rendered disabled and dimmed unless you also update login.astro to remove them from the rendered list.
5. packages/server/.env.example — Document env vars
Add the three new env vars (this is the canonical env example file):
EXAMPLE_CLIENT_ID=
EXAMPLE_CLIENT_SECRET=
EXAMPLE_CALLBACK_URL=https://your-domain.com/auth/callback
6. Tests to update
| File | What to change |
|---|---|
packages/server/tests/auth-handlers.test.ts |
Add provider to allProviders config object; add a redirect URL assertion test |
packages/server/tests/shared-guards.test.ts |
Remove new provider from "rejects unknown provider strings" if it was listed there |
OAuth Provider Registration
Each provider has a developer portal where you register the application:
- Redirect URI: Register both
http://localhost:3300/auth/callback(dev) andhttps://your-domain.com/auth/callback(prod). The server sendsredirect_uriin the authorize request and it must exactly match a registered URI. - Scopes: Request the minimum scope needed for login (e.g., Discord
identify, GitHubread:user, Googleopenid profile email). - Bot permissions: Not needed — the app only uses OAuth for user identity, not API access.
Local Verification Checklist
After implementation:
npx turbo run build— confirmsassertNeverexhaustiveness (build fails if a switch is missed)npx turbo run test— confirms shared guards and auth handler tests pass- Restart the dev server — a running
node dist/index.jsserves the old build; kill and restart it curl -s http://localhost:3300/auth/providers— confirm the new provider appears in the JSON array- Load
http://localhost:4321/login— confirm the button renders and is clickable - Click the button — confirm it redirects to the provider's authorize page with the correct
redirect_uri
Important: The dev server (
node dist/index.js) does not hot-reload. Afternpx turbo run build, you must kill and restart the server process for changes to take effect. The Astro dev server (npm run dev) does hot-reload.
04 同仓库更多 Skills
testing
Write and maintain tests for MUDdown packages. Covers vitest for the server and parser, fixture helpers, world integrity tests, and testing conventions.
room-creation
Create and modify MUDdown room files. Covers the Markdown+YAML structure, frontmatter fields, container blocks, bidirectional exits, item/NPC references, lighting, and region organization.
privacy
Audit and maintain privacy compliance for MUDdown. Covers the privacy policy, data collection practices, cookie/storage usage, and compliance testing.
persistence
Work with the database abstraction layer and account/character/world persistence. Covers the GameDatabase interface, SQLite adapter, save/load lifecycle, auth sessions, and testing patterns.
osc8-bridge
Add or modify OSC 8 hyperlink capabilities in the telnet bridge — NEW-ENVIRON (RFC 1572) negotiation, Mudlet/Fado/MudForge `send:` URIs, and per-scheme tooltip/menu metadata. Covers the capability pipeline from telnet negotiation through renderer output, the sanitization contract, and the word-wrap invariant.
npc-creation
Create and modify NPCs with branching dialogue trees for MUDdown. Covers the JSON format, dialogue node structure, location binding, mood/narrative fields, and the talk command flow.