feat(accounts): the hub as an OpenID Connect provider for T5DE Music (#23)
Second half of docs/music.md's phase 1: the hub as an OAuth 2.1 / OpenID Connect provider, with T5DE Music as its first client. Builds on #22 (merged). **Provider** (`@better-auth/oauth-provider` 1.7.26): issuer `API_URL/api/auth` (prod: `https://hub.t5de.dev/api/auth`), discovery at `/api/auth/.well-known/openid-configuration`, keys from the existing JWT plugin (Ed25519). The JWT plugin's `/token` route is off (nothing used it). Seven tables (migration `0022_oauth_provider`). - **Music** (`t5de-music`) is made at startup from `MUSIC_CLIENT_SECRET` and `MUSIC_REDIRECT_URIS`: trusted (no consent screen), confidential, PKCE required, HTTPS redirect URIs only (plain HTTP on localhost in development). Its secret is stored as a SHA-256 hash the hub supplies (`storeClientSecret`), so seeding and the plugin agree. Dynamic client registration stays off. - **Scopes**: `openid profile email offline_access`, `imvu` (the person's linked IMVU accounts, real IDs and names, in the ID token and userinfo: first-party sites only, as the plan says) and `imvu:link`. - **The hub's API as a resource**: Music asks for `resource=API_URL/api/v1` and gets a JWT access token (`at+jwt`, that audience). The API checks it against its own keys. Routes for sites (`linking`): `GET /api/v1/account/imvu` and the existing link routes (start, check, cancel, unlink), for any account including basic ones. Every other route answers such a token 403 `token_not_allowed`, and a token without `imvu:link` 403 `insufficient_scope`. **Website**: `/signin` opened by authorize ("Sign in with your T5DE account to continue to T5DE Music") sends people back to authorize once signed in, by password or Discord. `t5de_provider=discord` in Music's request starts Discord at once, so "Sign in with Discord" on Music goes straight to Discord. `/consent` for sites added later. `GET /api/v1/oauth/clients/:id` names the site. Second half of docs/music.md's phase 1: the hub as an OAuth 2.1 / OpenID Connect provider, with T5DE Music as its first client. Builds on #22 (merged). **Provider** (`@better-auth/oauth-provider` 1.7.26): issuer `API_URL/api/auth` (prod: `https://hub.t5de.dev/api/auth`), discovery at `/api/auth/.well-known/openid-configuration`, keys from the existing JWT plugin (Ed25519). The JWT plugin's `/token` route is off (nothing used it). Seven tables (migration `0022_oauth_provider`). - **Music** (`t5de-music`) is made at startup from `MUSIC_CLIENT_SECRET` and `MUSIC_REDIRECT_URIS`: trusted (no consent screen), confidential, PKCE required, HTTPS redirect URIs only (plain HTTP on localhost in development). Its secret is stored as a SHA-256 hash the hub supplies (`storeClientSecret`), so seeding and the plugin agree. Dynamic client registration stays off. - **Scopes**: `openid profile email offline_access`, `imvu` (the person's linked IMVU accounts, real IDs and names, in the ID token and userinfo: first-party sites only, as the plan says) and `imvu:link`. - **The hub's API as a resource**: Music asks for `resource=API_URL/api/v1` and gets a JWT access token (`at+jwt`, that audience). The API checks it against its own keys. Routes for sites (`linking`): `GET /api/v1/account/imvu` and the existing link routes (start, check, cancel, unlink), for any account including basic ones. Every other route answers such a token 403 `token_not_allowed`, and a token without `imvu:link` 403 `insufficient_scope`. **Website**: `/signin` opened by authorize ("Sign in with your T5DE account to continue to T5DE Music") sends people back to authorize once signed in, by password or Discord. `t5de_provider=discord` in Music's request starts Discord at once, so "Sign in with Discord" on Music goes straight to Discord. `/consent` for sites added later. `GET /api/v1/oauth/clients/:id` names the site. Tests: `apps/api/test/oidc.test.ts` runs Music's whole flow against the API (discovery, sign-in redirect with the hint, code + PKCE, token, ID token and userinfo claims, the access token on link routes and refused elsewhere, scopes, a basic account linking through Music). Full suite 75/75; `check-types` and `build` pass. Not checked in a browser yet. **Not in this PR** (later phases): merging a basic account into a member (`user.merged`), pairwise subjects and the console for third-party clients, `@imvu/verify` in place of the hub's link code. Deploying: `MUSIC_CLIENT_SECRET` (32+ random characters, shared with Music's stack) and `MUSIC_REDIRECT_URIS=https://music.t5de.dev/api/auth/callback` in the hub stacks (dhkatz/infra), with Music's own stack. Tests: `apps/api/test/oidc.test.ts` runs Music's whole flow against the API (discovery, sign-in redirect with the hint, code + PKCE, token, ID token and userinfo claims, the access token on link routes and refused elsewhere, scopes, a basic account linking through Music). Full suite 75/75; `check-types` and `build` pass. Not checked in a browser yet. **Not in this PR** (later phases): merging a basic account into a member (`user.merged`), pairwise subjects and the console for third-party clients, `@imvu/verify` in place of the hub's link code. Deploying: `MUSIC_CLIENT_SECRET` (32+ random characters, shared with Music's stack) and `MUSIC_REDIRECT_URIS=https://music.t5de.dev/api/auth/callback` in the hub stacks (dhkatz/infra), with Music's own stack. Co-authored-by: dhkatz <[email protected]>
This commit was merged in pull request #23.
This commit is contained in:
1 parent
f05874f800
commit
df42b7833a
20 files changed
+6531
-29
No files matched your search
+26
-1
@@ -3,7 +3,7 @@
|
||||
`apps/api` (Elysia on Bun). The route definitions in `apps/api/src/app.ts` are the reference: their schemas validate
|
||||
requests and type the website's client (Eden). This is the overview.
|
||||
|
||||
- `/api/auth/*`: Better Auth (accounts, sessions, device sign-in, JWT keys).
|
||||
- `/api/auth/*`: Better Auth (accounts, sessions, device sign-in, JWT keys, and the OpenID Connect provider).
|
||||
- `/api/v1/*`: the hub's own routes.
|
||||
|
||||
The website reaches the API through its own origin (Next.js rewrites `/api` to it), so sessions are first-party
|
||||
@@ -30,6 +30,31 @@ is. Codes: `invalid`, `signed_out`, `forbidden`, `not_found`, `no_such_imvu_acco
|
||||
| `GET /api/v1/hub` | (anyone) `{registration, discord}`: registration `open` or `closed`, and whether Discord sign-in is on |
|
||||
| `POST /api/v1/account/finish` | (a basic account) `{username, password}` → `{person}`: it becomes a member (`invalid_username`, `invalid_password`, `username_taken`, `already_member`); with registration closed it then waits for approval. Discord stays linked. |
|
||||
|
||||
## Signing in on T5DE's other sites (OpenID Connect)
|
||||
|
||||
The hub is an OAuth 2.1 / OpenID Connect provider (Better Auth's `@better-auth/oauth-provider`) for T5DE's own sites,
|
||||
Music first (docs/music.md, The OIDC provider). The issuer is `API_URL/api/auth`; discovery at
|
||||
`/api/auth/.well-known/openid-configuration`, keys at `/api/auth/jwks` (Ed25519, the same keys as the JWT plugin).
|
||||
|
||||
- **Clients**: first-party sites are made at startup from the environment (`MUSIC_CLIENT_SECRET`,
|
||||
`MUSIC_REDIRECT_URIS`: client ID `t5de-music`), trusted (no consent screen), confidential (`client_secret_basic`),
|
||||
PKCE required, HTTPS redirect URIs (plain HTTP on localhost in development). Dynamic registration is off.
|
||||
- **Flow**: authorization code. `/api/auth/oauth2/authorize` sends people who aren't signed in to the website's
|
||||
`/signin` with the request and a signature; once signed in (password or Discord) the page sends them back to
|
||||
authorize, which returns them to the site with a code. `t5de_provider=discord` in the request starts Discord
|
||||
sign-in at once (a site's "Sign in with Discord"). Other sites' requests show `/consent`.
|
||||
- **Tokens**: `/api/auth/oauth2/token`, `/userinfo`, `/introspect`, `/revoke`. Ask for `resource=API_URL/api/v1` to
|
||||
get an access token for the hub's API (a JWT, `typ: at+jwt`, audience that resource), needed for the routes below.
|
||||
- **Scopes**: `openid`, `profile` (`name`, `preferred_username` for members), `email`, `offline_access` (a refresh
|
||||
token), `imvu` (first-party only: `imvu: [{id, username}]`, the person's linked IMVU accounts, in the ID token and
|
||||
userinfo), `imvu:link` (the hub's link routes with the person's access token).
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| `GET /api/v1/oauth/clients/:clientId` | (anyone) `{client: {name, firstParty}}`: for the sign-in and consent pages |
|
||||
| `GET /api/v1/account/imvu` | (`imvu:link` token, or the website) `{links, challenges, linkCap, canLink}` |
|
||||
| `POST /api/v1/account/links`, `POST .../:imvu/check`, `DELETE /api/v1/account/challenges/:imvu`, `DELETE /api/v1/account/links/:imvu` | also take an `imvu:link` token, for any account (basic ones too); see the website routes below. Other routes answer such tokens 403 `token_not_allowed`, and a token without the scope gets 403 `insufficient_scope`. |
|
||||
|
||||
## Proxies
|
||||
|
||||
| | |
|
||||
|
||||
Reference in new issue
Block a user