@protobase/cli 0.105.2 → 0.105.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/package.js +1 -1
- package/dist/dev/api-forward.js +3 -3
- package/package.json +8 -8
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
- package/skills/protobase/references/reference/auth.md +61 -1
- package/skills/protobase/references/reference/cli.md +1 -1
- package/skills/protobase/references/reference/config/sign-in.md +13 -2
package/dist/cli/package.js
CHANGED
package/dist/dev/api-forward.js
CHANGED
|
@@ -6,10 +6,10 @@ import { request } from "node:http";
|
|
|
6
6
|
//#region src/dev/api-forward.ts
|
|
7
7
|
/**
|
|
8
8
|
* The requests the API process answers: everything under /api, the passkey origins at /.well-known/webauthn, the OAuth
|
|
9
|
-
* discovery documents MCP clients read (`oauthWellKnownPaths`), below which a
|
|
10
|
-
* (`withDevServiceWorker`). Vite serves the rest.
|
|
9
|
+
* discovery documents MCP clients and the OpenID provider's clients read (`oauthWellKnownPaths`), below which a
|
|
10
|
+
* resource's own one is, and the push worker (`withDevServiceWorker`). Vite serves the rest.
|
|
11
11
|
*/
|
|
12
|
-
const apiRequestPattern = /^(\/api(\/|\?|$)|\/\.well-known\/webauthn(\?|$)|\/\.well-known\/oauth-
|
|
12
|
+
const apiRequestPattern = /^(\/api(\/|\?|$)|\/\.well-known\/webauthn(\?|$)|\/\.well-known\/(oauth-authorization-server|oauth-protected-resource|openid-configuration)(\/|\?|$)|\/protobase\.sw\.js(\?|$))/;
|
|
13
13
|
const isApiRequest = (url) => apiRequestPattern.test(url);
|
|
14
14
|
const hopByHop = /* @__PURE__ */ new Set([
|
|
15
15
|
"connection",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.105.
|
|
3
|
+
"version": "0.105.3",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.105.
|
|
47
|
-
"@protobase/layout": "0.105.
|
|
48
|
-
"@protobase/query": "0.105.
|
|
49
|
-
"@protobase/schema": "0.105.
|
|
50
|
-
"@protobase/server": "0.105.
|
|
51
|
-
"@protobase/ui": "0.105.
|
|
52
|
-
"@protobase/workflows": "0.105.
|
|
46
|
+
"@protobase/config": "0.105.3",
|
|
47
|
+
"@protobase/layout": "0.105.3",
|
|
48
|
+
"@protobase/query": "0.105.3",
|
|
49
|
+
"@protobase/schema": "0.105.3",
|
|
50
|
+
"@protobase/server": "0.105.3",
|
|
51
|
+
"@protobase/ui": "0.105.3",
|
|
52
|
+
"@protobase/workflows": "0.105.3",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -32,6 +32,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
32
32
|
- [SAML sign-in](../reference/auth.md#sign-in-with-saml): People sign in through any SAML provider.
|
|
33
33
|
- [OpenID Connect provider](../reference/auth.md#platform-sign-in-provider): A host adds an OpenID Connect provider for people who already have an account.
|
|
34
34
|
- [Token sign-in](../reference/auth.md#token-sign-in): A client that holds a fresh ID token from that provider for this app signs in with it once, in place of an emailed code, and gets the app's own session, with the app's second step when one is on.
|
|
35
|
+
- [Being an OpenID provider](../reference/auth.md#openid-provider-for-other-apps): The app vouches for its people's verified addresses to other apps its admin registers, which sign them in without asking them to allow it, and lets a phone app get a sign-in token for each of those apps, or for any app at the origins it names by pattern, without a browser.
|
|
35
36
|
- [Staff sign-in](../reference/auth.md#staff-sign-in): The team that runs an app signs in as a person to help them, with a reason and a log entry.
|
|
36
37
|
- [Roles](../reference/auth.md#roles): A user holds one or more roles and switches between them without signing in again.
|
|
37
38
|
- [Organizations](../reference/auth.md#organizations): People work in one organization at a time, see only its records, and are invited with their own roles.
|
|
@@ -524,7 +524,7 @@ PROTOBASE_OPERATOR_NAME="Protobase Cloud" # shown as "Continue
|
|
|
524
524
|
PROTOBASE_OPERATOR_GROUP=protobase-staff-access # the default
|
|
525
525
|
```
|
|
526
526
|
|
|
527
|
-
Set the first three together or none: some but not all of them stops the app at start with an error. In the config, `auth.operator` takes the same settings and a few more, and `false` turns staff sign-in off whatever the environment says:
|
|
527
|
+
Set the first three together or none: some but not all of them stops the app at start with an error. The one exception is [token sign-in alone](#token-sign-in): `PROTOBASE_SIGN_IN_ISSUER` with `PROTOBASE_SIGN_IN_TOKENS=true`, and no secret. In the config, `auth.operator` takes the same settings and a few more, and `false` turns staff sign-in off whatever the environment says:
|
|
528
528
|
|
|
529
529
|
```ts
|
|
530
530
|
auth: { operator: { issuer, clientId, clientSecret, name: 'Support', group: 'support-leads', scopes: ['groups'], acrValues: ['gold'], sessionMinutes: 15 } }
|
|
@@ -628,6 +628,7 @@ auth: { signInProvider: { issuer, clientId, clientSecret, tokenSignIn: true } }
|
|
|
628
628
|
The client posts `POST /api/auth/sign-in/social` with `{ "provider": "<provider id>", "idToken": { "token": "<ID token>" } }`, as Better Auth's client sends `signIn.social({ provider, idToken: { token } })`, and gets the session cookie with `{ redirect: false, user }`, or `{ twoFactorRedirect: true, twoFactorMethods }` when the [second step](#two-factor-authentication) is due, which it finishes as after a password. Then `GET /api/auth/token` gives it the app's API token as for any session.
|
|
629
629
|
|
|
630
630
|
- **Only this app's own provider:** the app trusts the one provider it is configured with, and a token only for this app. The token must be signed with a key the provider publishes (its discovery's `jwks_uri`) with an asymmetric algorithm, come from the configured issuer, and have this app's client id as its one audience, so a token issued for another app is never accepted here. It must carry an `email` (a `jti` is not needed), live at most 5 minutes from `iat` to `exp`, and have been issued within the last 5 minutes (30 seconds of clock skew allowed). Otherwise it is refused with `401 INVALID_TOKEN`.
|
|
631
|
+
- **Alone, without a client secret:** with the issuer and `PROTOBASE_SIGN_IN_TOKENS=true` but no `PROTOBASE_SIGN_IN_CLIENT_SECRET` (`signInProvider: { issuer, tokenSignIn: true }`), the app is no client of the provider's: it takes tokens whose audience is the origin of its `url`, or `PROTOBASE_SIGN_IN_CLIENT_ID` when set, as from the [token exchange](#token-exchange) of an OpenID provider's `audiences`. Nobody is sent through the provider's pages: the sign-in page shows no button for it, and starting or connecting it answers `403 PROVIDER_PAGES_OFF`.
|
|
631
632
|
- **Once:** each token signs in once. Its issuer and the SHA-256 of its claims are kept in the `verification` table until it expires, with no migration, and a second use answers `401 TOKEN_USED`. The claims count, not the token's text, so the same token written another way is refused too, and so is a second token with exactly the same claims.
|
|
632
633
|
- **Who it signs in:** as through the provider's pages, the account linked to the provider's `sub`, else the account with the address the provider vouches for (`email_verified`), which it links. Nobody is signed up (`401`), and a banned person is refused.
|
|
633
634
|
- **Never recent:** the client can mint a fresh session at will, so a session a token began never counts as [recently signed in](#confirming-an-account-change). Adding a passkey, unlinking a provider, making a personal access token or deleting the account asks it to confirm it's them in place first, and it is never a [strong sign-in](#recent-strong-sign-in) until it confirms it's them.
|
|
@@ -863,6 +864,65 @@ auth: { mcp: true, oauth: { api: true } }
|
|
|
863
864
|
- Notifications and calls refuse these tokens, as they refuse an MCP client's.
|
|
864
865
|
- <gap>The app's API cannot take DPoP-bound access tokens because checking a proof against the API's URLs is not implemented.</gap> A token bound to a key is refused when it is sent as a bearer token.
|
|
865
866
|
|
|
867
|
+
## OpenID provider for other apps
|
|
868
|
+
|
|
869
|
+
With `openIdProvider`, the app is an OpenID provider for the clients its admins register, such as other apps that let people sign in with it: a person signs in on the app's own pages, as they always do, and the client gets an ID token that says who they are. Nobody is asked to allow a client, since only an admin registers one. A phone app the admin registers can also get ID tokens for every app at the origins `audiences` names, with no registration per app, through the [token exchange](#token-exchange).
|
|
870
|
+
|
|
871
|
+
```ts
|
|
872
|
+
auth: { openIdProvider: true }
|
|
873
|
+
auth: { openIdProvider: { connectPage: '/-/connect', audiences: ['https://*.example.app'] } }
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
- **Audiences** are https origins, exact (`https://shop.example.com`) or with one leading wildcard label (`https://*.example.app`, which stands for `shop.example.app` but not `example.app` or `a.b.example.app`). A wildcard needs two labels after it, and a pattern takes no port, path, query or user info; anything else stops the app at start. An app at such an origin gets ID tokens only from the token exchange: no browser is ever sent there, so an authorize whose client id or redirect URI is on such a host is refused (`400 invalid_request`), and so is registering a client with a redirect URI there (`400 REDIRECT_ON_AUDIENCE_HOST`).
|
|
877
|
+
|
|
878
|
+
- **Only registered clients.** Nothing registers itself: `/api/auth/oauth2/register` is closed, and so are the provider's own client management, consent, userinfo, introspection and logout endpoints. A client the admin did not register through the API below is refused with `400 invalid_client` at authorize and at the token endpoint, before anything else, and so is a client in the store from elsewhere, such as one an MCP client registered while the app had `mcp` on. A redirect URI must be one the client registered, character for character, so the person's browser is never sent with a code, or an error, to an address of someone else's.
|
|
879
|
+
- **Not with `mcp`.** MCP clients register themselves, and the provider of this mode is separate from MCP's, so the server refuses to start with both. Serve them from separate apps.
|
|
880
|
+
- **Discovery** is at `/.well-known/openid-configuration`, with the app's `url` as issuer, and the keys at `/api/auth/jwks`. A client uses the authorization code flow with PKCE, with `openid email profile`, and a `nonce`.
|
|
881
|
+
- **The ID token** is signed with the app's [signing keys](#signing-keys) (EdDSA) and lives 5 minutes. It carries `iss` (the app's `url`), `aud` (the client's id, alone), `sub` (the person's user id in this app), `email`, `email_verified`, and `name` when the person has one. It has no `jti`. Another Protobase app takes it as its [platform sign-in provider](#platform-sign-in-provider), through its pages or by [token sign-in](#token-sign-in).
|
|
882
|
+
- **Signing in** goes through the connect page (`connectPage`, default `/-/connect`), which signs the person in and goes straight on to the client. Someone who has not set up what the [sign-in policy](#sign-in-policy) requires is sent to the setup page first, and staff signed in as a person get no token.
|
|
883
|
+
|
|
884
|
+
### Registering clients
|
|
885
|
+
|
|
886
|
+
An admin registers, lists and deletes the clients with their own session; anyone else is refused with `403 ADMIN_ONLY`:
|
|
887
|
+
|
|
888
|
+
```http
|
|
889
|
+
POST /api/auth/openid-provider/clients
|
|
890
|
+
{ "name": "Shop", "redirectUris": ["https://shop.example.com/api/auth/callback/oidc"], "type": "confidential" }
|
|
891
|
+
→ { "clientId": "...", "clientSecret": "..." }
|
|
892
|
+
|
|
893
|
+
GET /api/auth/openid-provider/clients
|
|
894
|
+
→ [{ "clientId": "...", "name": "Shop", "redirectUris": [...], "type": "confidential", "exchange": false }]
|
|
895
|
+
|
|
896
|
+
POST /api/auth/openid-provider/clients/delete
|
|
897
|
+
{ "clientId": "..." }
|
|
898
|
+
```
|
|
899
|
+
|
|
900
|
+
- `confidential` is an app with a server, which authenticates with the secret it gets once, in a Basic header; `public` is an app on a device, such as a phone app, which has no secret and uses PKCE alone.
|
|
901
|
+
- Every client skips consent, must use PKCE, and gets the scopes `openid email profile`.
|
|
902
|
+
- `exchange: true` lets a client exchange its access token for ID tokens of the other clients (below), and gives it refresh tokens (`offline_access`). Only the app that signs people in on their device for the other apps should have it: it can sign its people in to every other client.
|
|
903
|
+
- Deleting a client deletes its tokens too, so its refresh tokens stop at once.
|
|
904
|
+
|
|
905
|
+
### Token exchange
|
|
906
|
+
|
|
907
|
+
A client registered with `exchange: true`, such as a phone app the person signed in to once, gets an ID token for another registered client, or for an origin of `audiences`, without a browser, and posts it to that app's [token sign-in](#token-sign-in). It is the token exchange of RFC 8693 at the token endpoint:
|
|
908
|
+
|
|
909
|
+
```http
|
|
910
|
+
POST /api/auth/oauth2/token
|
|
911
|
+
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
|
|
912
|
+
&client_id=<its own id>
|
|
913
|
+
&subject_token=<its access token>
|
|
914
|
+
&subject_token_type=urn:ietf:params:oauth:token-type:access_token
|
|
915
|
+
&requested_token_type=urn:ietf:params:oauth:token-type:id_token
|
|
916
|
+
&audience=<the other client's id, or an origin such as https://shop.example.app>
|
|
917
|
+
→ { "access_token": "<ID token>", "issued_token_type": "urn:ietf:params:oauth:token-type:id_token", "token_type": "N_A", "expires_in": 300 }
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
- **The subject is the caller's own person.** `subject_token` must be a live access token this app issued to the calling client itself: not an ID token, a refresh token or another client's token, not expired, revoked or from a session that ended. Otherwise it answers `400 invalid_grant`. A client without `exchange` gets `400 unauthorized_client`.
|
|
921
|
+
- **The audience is another registered client, or an origin of `audiences`**: not the caller, not an unknown client and not one the admin did not register (`400 invalid_target`). An origin is matched as the URL parser writes it, label by label, so `http://`, a port, a path or trailing slash, user info, upper case, an extra label (`a.b.example.app`) and look-alikes (`example.app.evil.com`, `evilexample.app`) are refused.
|
|
922
|
+
- **An ID token only.** The answer is an ID token for that client or origin alone, living 5 minutes, with the claims of the client's own sign-in; one for an origin has that origin as `aud`, and a `jti`. No access or refresh token for the other client leaves the app. `requested_token_type` and `subject_token_type` take only the values above (`400 invalid_request`).
|
|
923
|
+
- **A banned person, or one whose address is not verified,** gets none (`400 invalid_grant`). A ban after the token was issued is caught by the other app, which checks its own account at sign-in.
|
|
924
|
+
- The token endpoint takes 20 requests a minute per client address.
|
|
925
|
+
|
|
866
926
|
## Several origins
|
|
867
927
|
|
|
868
928
|
An app can be served on more than one origin, such as its platform address and the customer's own domain. `auth.origins` lists the others; it defaults to `PROTOBASE_ORIGINS`, which a platform sets:
|
|
@@ -253,7 +253,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
|
|
|
253
253
|
"server": "protobase.config.js",
|
|
254
254
|
"public": "public",
|
|
255
255
|
"spa": "index.html",
|
|
256
|
-
"api": ["/api", "/.well-known/oauth-authorization-server", "/.well-known/oauth-protected-resource"],
|
|
256
|
+
"api": ["/api", "/.well-known/oauth-authorization-server", "/.well-known/oauth-protected-resource", "/.well-known/openid-configuration"],
|
|
257
257
|
"theme": "protobase.theme.css",
|
|
258
258
|
"plugins": [
|
|
259
259
|
{ "name": "app", "path": "plugins/app/plugin.json", "api": 1, "protobase": ">=0.12.0", "fields": { "steps": ["enum"] } }
|
|
@@ -167,11 +167,11 @@ export default defineConfig(({ env }) => ({
|
|
|
167
167
|
|
|
168
168
|
## auth.signInProvider
|
|
169
169
|
|
|
170
|
-
- **Type:** `{ issuer: string; clientId
|
|
170
|
+
- **Type:** `{ issuer: string; clientId?: string; clientSecret?: string; provider?: string; name?: string; scopes?: string[]; tokenSignIn?: boolean } | false`
|
|
171
171
|
- **Default:** the provider of the environment variables below, when set
|
|
172
172
|
- **Environment variables:** `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET`, and optionally `PROTOBASE_SIGN_IN_PROVIDER`, `PROTOBASE_SIGN_IN_NAME` and `PROTOBASE_SIGN_IN_TOKENS` (`true` or `false`)
|
|
173
173
|
|
|
174
|
-
An OpenID Connect provider the platform adds for people who already have an account; it never signs anyone up. `provider` is its id (default `oidc`), `name` its button's name, and `tokenSignIn: true` lets a client sign in with a fresh ID token the provider issued for this app ([Token sign-in](../auth.md#token-sign-in), default off). `false` turns it off whatever the environment says. Left out when `socialProviders` has a provider with the same id. See [Platform sign-in provider](../auth.md#platform-sign-in-provider).
|
|
174
|
+
An OpenID Connect provider the platform adds for people who already have an account; it never signs anyone up. `provider` is its id (default `oidc`), `name` its button's name, and `tokenSignIn: true` lets a client sign in with a fresh ID token the provider issued for this app ([Token sign-in](../auth.md#token-sign-in), default off). `false` turns it off whatever the environment says. Left out when `socialProviders` has a provider with the same id. Without `clientSecret` it signs in by token sign-in alone, which `tokenSignIn: true` must then turn on, with tokens for the origin of `url` unless `clientId` names another. See [Platform sign-in provider](../auth.md#platform-sign-in-provider).
|
|
175
175
|
|
|
176
176
|
```ts
|
|
177
177
|
export default defineConfig({ auth: { signInProvider: false } })
|
|
@@ -317,6 +317,17 @@ What the OAuth provider of [`auth.mcp`](#authmcp) serves besides MCP. `api: true
|
|
|
317
317
|
export default defineConfig({ auth: { mcp: true, oauth: { api: true } } })
|
|
318
318
|
```
|
|
319
319
|
|
|
320
|
+
## auth.openIdProvider
|
|
321
|
+
|
|
322
|
+
- **Type:** `true | { connectPage?: string; audiences?: string[] }`
|
|
323
|
+
- **Default:** off
|
|
324
|
+
|
|
325
|
+
Makes the app an OpenID provider for the clients its admins register at `/api/auth/openid-provider/clients`, such as other apps that sign people in with it: they get an ID token with the person's `sub`, `email` and `email_verified`, without asking the person to allow them, and nothing else can register. A client allowed to exchange gets ID tokens for the other clients, and for the origins `audiences` names as patterns such as `https://*.example.app`, without a browser. `connectPage` is the page people sign in on (default `/-/connect`). Not with [`auth.mcp`](#authmcp); the server refuses to start with both. See [OpenID provider for other apps](../auth.md#openid-provider-for-other-apps).
|
|
326
|
+
|
|
327
|
+
```ts
|
|
328
|
+
export default defineConfig({ auth: { openIdProvider: true } })
|
|
329
|
+
```
|
|
330
|
+
|
|
320
331
|
## auth.personalAccessTokens
|
|
321
332
|
|
|
322
333
|
- **Type:** `{ prefix: string }`
|