@protobase/cli 0.105.3 → 0.106.1
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/package.json +8 -8
- package/skills/protobase/references/features/sign-in-and-accounts.md +2 -1
- package/skills/protobase/references/guides/deploy.md +1 -1
- package/skills/protobase/references/reference/auth.md +48 -19
- package/skills/protobase/references/reference/cli.md +2 -2
- package/skills/protobase/references/reference/config/sign-in.md +6 -6
package/dist/cli/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.106.1",
|
|
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.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.106.1",
|
|
47
|
+
"@protobase/layout": "0.106.1",
|
|
48
|
+
"@protobase/query": "0.106.1",
|
|
49
|
+
"@protobase/schema": "0.106.1",
|
|
50
|
+
"@protobase/server": "0.106.1",
|
|
51
|
+
"@protobase/ui": "0.106.1",
|
|
52
|
+
"@protobase/workflows": "0.106.1",
|
|
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",
|
|
@@ -30,7 +30,8 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
30
30
|
- [Sign-in links](../reference/auth.md#sign-in-links-and-connected-accounts): A link signs someone in with a sign-in provider at once, without the sign-in page.
|
|
31
31
|
- [Connected accounts](../reference/auth.md#sign-in-links-and-connected-accounts): People link GitHub or another sign-in provider to their account from the account page.
|
|
32
32
|
- [SAML sign-in](../reference/auth.md#sign-in-with-saml): People sign in through any SAML provider.
|
|
33
|
-
- [OpenID Connect
|
|
33
|
+
- [OpenID Connect providers](../reference/auth.md#platform-sign-in-providers): A host adds OpenID Connect providers for people who already have an account, each with its own id, name and ways to sign in.
|
|
34
|
+
- [Devices](../reference/auth.md#device-accounts): A provider that signs in phones links each device as an account of its own, which the person signs out for good from the Devices tab.
|
|
34
35
|
- [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
36
|
- [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.
|
|
36
37
|
- [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.
|
|
@@ -28,7 +28,7 @@ dist/
|
|
|
28
28
|
plugins and the app's version
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (`/api` and the two OAuth discovery documents of [MCP clients](../reference/auth.md#oauth-for-mcp-clients)), and `/.well-known/webauthn` for an app on [several origins](../reference/auth.md#several-origins), which the manifest does not list, so loading the UI never needs a running container. With the UI it sends `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, as `protobase serve` does, so no other site frames the app's pages. The runtime serves the API alone; `protobase serve dist` serves the whole folder the same way, to check a bundle locally. The host passes `DATABASE_URL`, `PORT` (default 8787) and optionally `PROTOBASE_DB_CONNECTIONS` (the connections the app may open, so its functions and jobs leave one to requests, see [`serve`](../reference/cli.md#serve)), `REQUEST_LOG`, `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (the mail server and sender for [password reset](../reference/auth.md#password-reset) and emailed sign-in codes) `PROTOBASE_APP_NAME` (the app's name in that mail, see [`name`](../reference/config/app.md#name)) `PROTOBASE_SIGN_IN_*` (
|
|
31
|
+
The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (`/api` and the two OAuth discovery documents of [MCP clients](../reference/auth.md#oauth-for-mcp-clients)), and `/.well-known/webauthn` for an app on [several origins](../reference/auth.md#several-origins), which the manifest does not list, so loading the UI never needs a running container. With the UI it sends `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, as `protobase serve` does, so no other site frames the app's pages. The runtime serves the API alone; `protobase serve dist` serves the whole folder the same way, to check a bundle locally. The host passes `DATABASE_URL`, `PORT` (default 8787) and optionally `PROTOBASE_DB_CONNECTIONS` (the connections the app may open, so its functions and jobs leave one to requests, see [`serve`](../reference/cli.md#serve)), `REQUEST_LOG`, `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (the mail server and sender for [password reset](../reference/auth.md#password-reset) and emailed sign-in codes) `PROTOBASE_APP_NAME` (the app's name in that mail, see [`name`](../reference/config/app.md#name)) `PROTOBASE_SIGN_IN_*` (providers people with an account sign in with, the [platform sign-in providers](../reference/auth.md#platform-sign-in-providers)) `PROTOBASE_OPERATOR_*` (the provider its staff sign in with for [staff sign-in](../reference/auth.md#staff-sign-in)), `PROTOBASE_ORIGINS` and `PROTOBASE_PASSKEY_DOMAIN` (the app's [other origins](../reference/auth.md#several-origins) and its passkey domain) `PROTOBASE_CORS_ORIGINS` (the websites that may call its API, see [CORS](../reference/api.md#cors)), `PROTOBASE_TRUSTED_PROXIES` (the proxies in front of the runtime, whose `X-Forwarded-For` names the client the sign-in limits count, see [Client addresses](../reference/auth.md#client-addresses)) and `PROTOBASE_SENTRY_DSN` (the app's [error tracker](../reference/api.md#error-reporting)), `PROTOBASE_URL` and `PROTOBASE_SECRET` (the app's address and secret, unless its config sets [`url` and `secret`](../reference/config/app.md)), plus the project's own settings, which its config reads where it serves. The runtime and the config module are plain JavaScript for Bun: no install, no TypeScript, no writes. The runtime supplies protobase and the dependencies it runs on the server (`pg`, `postgres`, `kysely`, `better-auth`, ...), so the config module carries only the project's code and the other packages it uses. Each release lists the modules it supplies in `@protobase/cli/host-modules.json` (see [the config module](../reference/cli.md#the-config-module)), for a host to check a bundle's imports against the runtime that serves it. The manifest's `protobase` is the version the bundle was built with, the building CLI's in a [bundled project](../reference/versioning.md#bundled-and-locked-projects) and the installed one in a locked project, and the host serves the bundle on the runtime of that version (see [Versioning](../reference/versioning.md#bundles-and-runtimes)). The manifest format and the routing rules are in the CLI reference: [`build`](../reference/cli.md#build), [`build-serve`](../reference/cli.md#build-serve) and [`serve`](../reference/cli.md#serve).
|
|
32
32
|
|
|
33
33
|
## Migrations
|
|
34
34
|
|
|
@@ -96,7 +96,7 @@ The store's migrations then make nothing of the user table, which a migration of
|
|
|
96
96
|
| `PROTOBASE_CORS_ORIGINS` | other websites whose browser code may call the API, `*` or comma separated http and https origins, passed by the platform; see [CORS](api.md#cors) |
|
|
97
97
|
| `PROTOBASE_SMTP_URL`, `PROTOBASE_MAIL_FROM` | the mail server and sender for [password reset](#password-reset), [emailed sign-in codes](#emailed-sign-in-codes), emailed [two-factor](#two-factor-authentication) codes and [open sign-up](#open-sign-up), passed by the platform; all four are off without them |
|
|
98
98
|
| `PROTOBASE_APP_NAME` | the app's name, passed by the platform: it overrides `name` |
|
|
99
|
-
| `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | the [platform sign-in provider](#platform-sign-in-
|
|
99
|
+
| `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | the [platform sign-in provider](#platform-sign-in-providers) for people who have an account, passed by the platform; off without them. `PROTOBASE_SIGN_IN_PROVIDER`, `PROTOBASE_SIGN_IN_NAME`, `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS`, `PROTOBASE_SIGN_IN_HIDDEN` and `PROTOBASE_SIGN_IN_DEVICES` are optional, and `PROTOBASE_SIGN_IN_TOKENS=true` turns on its [token sign-in](#token-sign-in). `PROTOBASE_SIGN_IN_2_ISSUER` and so on add [more providers](#more-than-one-provider) |
|
|
100
100
|
| `PROTOBASE_OPERATOR_ISSUER`, `PROTOBASE_OPERATOR_CLIENT_ID`, `PROTOBASE_OPERATOR_CLIENT_SECRET` | the [operator provider](#operator-provider) its staff sign in with to sign in as people, passed by the platform; staff sign-in is off without them. `PROTOBASE_OPERATOR_NAME` and `PROTOBASE_OPERATOR_GROUP` are optional |
|
|
101
101
|
| `PROTOBASE_TRUSTED_PROXIES` | the proxies in front of `protobase serve`, addresses or CIDR ranges, comma separated, such as `172.30.87.1`, the Docker network's gateway in the [compose template](../guides/deploy.md#compose-template); see [Client addresses](#client-addresses) |
|
|
102
102
|
|
|
@@ -278,7 +278,7 @@ Checks of the signed-in account's current password are limited to 5 a minute for
|
|
|
278
278
|
|
|
279
279
|
On the [account page](#account-page), the `Password` block does both: with a password, it asks for the current one and the new one twice, and says the other devices are signed out; without one, it sets the first, and nobody is signed out. While the sign-in policy turns passwords off, or in a staff session, it only says so.
|
|
280
280
|
|
|
281
|
-
The [account page](#account-page)'s Devices tab lists the sessions with this one first and marked, a Sign out on each other one and Sign out of all other devices. It names each by its browser and system from the user agent, and a staff session by the operator alone, such as "Protobase staff" with when it signed in and until when, never the staff member.
|
|
281
|
+
The [account page](#account-page)'s Devices tab lists the sessions with this one first and marked, a Sign out on each other one and Sign out of all other devices. It names each by its browser and system from the user agent, and a staff session by the operator alone, such as "Protobase staff" with when it signed in and until when, never the staff member. Devices a [platform provider of devices](#device-accounts) links are listed by their own name, each with the sessions it began.
|
|
282
282
|
|
|
283
283
|
## Deleting the account
|
|
284
284
|
|
|
@@ -416,7 +416,7 @@ On their account page, people turn on a second step after a password or an email
|
|
|
416
416
|
|
|
417
417
|
Turning it on, off, or making new backup codes asks for the account's password when it has one. Without one, turning it on, reading the authenticator link (`/two-factor/get-totp-uri`) or making new backup codes from a session that signed in more than a day ago asks to [confirm it's them](#confirming-an-account-change) first, and the account page asks for it in place. At sign-in, a correct password or code, or a [sign-in token](#token-sign-in), answers `{ "twoFactorRedirect": true, "twoFactorMethods": ["totp", "otp"] }` instead of a session, and `POST /api/auth/two-factor/verify-totp`, `verify-otp` or `verify-backup-code` with `{ code, trustDevice? }` finishes it; `trustDevice` skips the step in that browser for 30 days. Ten wrong codes in a row lock the account's second step for 15 minutes.
|
|
418
418
|
|
|
419
|
-
Signing in through a provider's pages is one factor too, for the app's own [providers](#sign-in-with-github), the [platform's](#platform-sign-in-
|
|
419
|
+
Signing in through a provider's pages is one factor too, for the app's own [providers](#sign-in-with-github), the [platform's](#platform-sign-in-providers) and [SAML](#sign-in-with-saml) ones alike, since the app cannot check the provider's own second step. A person who turned the second step on comes back from the provider to the page they started from with `?second-step=<methods>`, such as `?second-step=totp`, the two-factor cookie and no session, and the sign-in page asks for the step there. <gap>A sign-in through the [GoTrue-compatible](#supabase-js-and-supabasessr) provider route cannot take the second step, because the GoTrue-compatible endpoints do not offer one; a person who turned it on is sent back with `error=access_denied`, as a password sign-in there answers `insufficient_aal`.</gap>
|
|
420
420
|
|
|
421
421
|
## Recent strong sign-in
|
|
422
422
|
|
|
@@ -477,13 +477,13 @@ The server stores the policy in the `sign_in_policy` table, one row per save (th
|
|
|
477
477
|
- **Required:** someone who signs in without it is sent to set it up first. The server holds back API tokens until then (`GET /api/auth/token` answers `403`, `SIGN_IN_SETUP_REQUIRED`), and refuses to turn two-factor authentication off or to remove the last passkey.
|
|
478
478
|
- Signed-in people keep their session after a change; a newly required method is asked for at their next token refresh, within 15 minutes.
|
|
479
479
|
- **Staff sign-in as a person** shows only with an [operator provider](#operator-provider). Off refuses [staff sign-in](#staff-sign-in) (`403`, `SIGN_IN_METHOD_FORBIDDEN`); Email the person mails the person each time, and needs mail: without it the server refuses to save it, and a saved one turns staff sign-in off until mail is back.
|
|
480
|
-
- **Sign in with ... through the platform** shows only with
|
|
480
|
+
- **Sign in with ... through the platform** shows only with [platform sign-in providers](#platform-sign-in-providers), and names them all. Off refuses starting, finishing and connecting every one of them, and their [token sign-in](#token-sign-in) (`403`, `SIGN_IN_METHOD_FORBIDDEN`), and the sign-in page leaves it out. It applies as Off while passkeys are Required, as it signs in without one. While two-factor authentication is Required it stays on: the [second step](#two-factor-authentication) follows it, and someone who has none yet sets it up first.
|
|
481
481
|
|
|
482
482
|
The server refuses a policy (`400`, `SIGN_IN_POLICY_REFUSED`, with the reason) that would lock people out: passwords and emailed codes both off (someone without a passkey could not sign in), passwords off without mail, two-factor authentication required with passwords off (turning it on asks for the password), or a policy the saving admin could not sign in with. Emailed codes need mail: without `PROTOBASE_SMTP_URL` they are off whatever the policy says, and so that a policy saved with mail cannot lock everyone out once mail goes away, password sign-in is then on as well.
|
|
483
483
|
|
|
484
|
-
The endpoints, for admins: `GET /api/auth/policy/sign-in` answers `{ policy, effective, mail, operator?,
|
|
484
|
+
The endpoints, for admins: `GET /api/auth/policy/sign-in` answers `{ policy, effective, mail, operator?, platformProviders?, savedAt?, savedBy? }` (`effective` is the policy as it applies now, `operator` the operator provider's name, `platformProviders` the names of the platform's sign-in providers), and `POST /api/auth/policy/sign-in` with `{ password, emailCode, passkey, twoFactor, staffAccess, platformSignIn }` saves one. `GET /api/auth/account/sign-in-methods` tells the signed-in user the policy, what their account has (`password`, `passkeys`, `twoFactor`, `authenticatorApp`) and what it still has to set up (`missing`).
|
|
485
485
|
|
|
486
|
-
Sign-in providers the project configures in code, such as its own GitHub app, are not covered by the policy;
|
|
486
|
+
Sign-in providers the project configures in code, such as its own GitHub app, are not covered by the policy; those the platform adds are. Neither are roles: the policy is the same for everyone.
|
|
487
487
|
|
|
488
488
|
## Staff sign-in
|
|
489
489
|
|
|
@@ -535,7 +535,7 @@ auth: { operator: false }
|
|
|
535
535
|
|
|
536
536
|
## Sign-in with GitHub
|
|
537
537
|
|
|
538
|
-
Projects have no sign-in provider of their own by default (a platform can add [one](#platform-sign-in-
|
|
538
|
+
Projects have no sign-in provider of their own by default (a platform can add [one](#platform-sign-in-providers)). `auth.socialProviders` adds Better Auth's [social providers](https://www.better-auth.com/docs/authentication/github), and the sign-in page shows "Continue with {name}" for each, such as "Continue with GitHub" with GitHub's mark for `github`:
|
|
539
539
|
|
|
540
540
|
```ts
|
|
541
541
|
export default defineConfig(({ env }) => ({
|
|
@@ -552,7 +552,7 @@ export default defineConfig(({ env }) => ({
|
|
|
552
552
|
|
|
553
553
|
### Sign-in links and connected accounts
|
|
554
554
|
|
|
555
|
-
These work for every provider, the project's own and the [platform's](#platform-sign-in-
|
|
555
|
+
These work for every provider, the project's own and the [platform's](#platform-sign-in-providers):
|
|
556
556
|
|
|
557
557
|
- **Sign-in links:** `https://<app>/?sign-in=github` starts signing in with `github` at once, showing only "Signing in with GitHub" while the browser leaves, so someone the provider knows lands signed in without a sign-in page. A refusal comes back to the sign-in page with the reason (`?error=<code>`, for example `signup_disabled`), and does not start again. Someone signed in already just opens the app.
|
|
558
558
|
- **Connected accounts:** the [account page](#account-page)'s **Sign-in & security** tab lists the providers and offers "Connect GitHub" for one the account is not linked to. Connecting signs in at the provider and links that account whatever its address (`accountLinking.allowDifferentEmails`, which applies only to this explicit link by someone signed in). A provider account linked to another person already is refused (`account_already_linked_to_different_user`); a [staff session](#staff-sign-in) cannot link.
|
|
@@ -586,9 +586,9 @@ Instead of the metadata XML, `idp` takes the provider's entity ID, sign-in URL a
|
|
|
586
586
|
- <gap>SAML providers cannot be kept per organization yet.</gap>
|
|
587
587
|
- <gap>SAML sign-in does not support signed or encrypted requests yet.</gap>
|
|
588
588
|
|
|
589
|
-
## Platform sign-in
|
|
589
|
+
## Platform sign-in providers
|
|
590
590
|
|
|
591
|
-
A platform that hosts the app can add
|
|
591
|
+
A platform that hosts the app can add sign-in providers for the people who have an account in it: any OpenID Connect providers, passed in the environment, each with an id of its own. A list of one is the common case. Protobase Cloud passes its own, so people sign in with GitHub through the Protobase GitHub App; a self-hosted app passes [Dex, Keycloak](#self-hosting-with-dex-or-keycloak) or the like.
|
|
592
592
|
|
|
593
593
|
```sh
|
|
594
594
|
PROTOBASE_SIGN_IN_ISSUER=https://auth.example.com # its discovery is <issuer>/.well-known/openid-configuration
|
|
@@ -604,15 +604,44 @@ Register the app with the provider as a confidential client with the redirect UR
|
|
|
604
604
|
- **The project's own provider wins:** with `socialProviders.github` in code and `PROTOBASE_SIGN_IN_PROVIDER=github`, the project's GitHub app handles the sign-in and the platform's is left out.
|
|
605
605
|
- **The provider id:** set `PROTOBASE_SIGN_IN_PROVIDER=github` only when the provider's `sub` is the GitHub user id, as Protobase Cloud's is. Its links are then those of Better Auth's own GitHub provider, so an app that later brings its own GitHub app keeps every person's link. Dex's and Keycloak's `sub` is their own id, so keep the default `oidc` for them.
|
|
606
606
|
- **Startup:** the provider's settings are read when the app starts; when they cannot be, the provider is left out until the next start (the status and sign-in page do not offer it) and every other way to sign in works.
|
|
607
|
-
-
|
|
607
|
+
- **Linking by address, safely:** a provider's first sign-in for someone links their account only when the token says the provider verified the address (`email_verified: true`) and the account's own address is verified. Once linked, the link alone finds them: the provider's id and `sub`, whatever address the token carries later. A person linked to one subject of a provider is not linked to a second one by address (`403 PROVIDER_ACCOUNT_LINKED`), unless the provider signs in [devices](#device-accounts). The store holds each provider's account once, and for a provider that links one subject per person, one account per person (unique indexes on the provider and account id, and on the provider and person, auth store migration 11), so two first sign-ins at the same moment link one, whether they bring the same subject or two.
|
|
608
|
+
- The [sign-in policy](#sign-in-policy) has one row for every one of them, and `GET /api/auth/status` names those with a button as `platformProviders: [{ provider, name }]` besides listing them in `socialProviders`.
|
|
608
609
|
|
|
609
|
-
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.
|
|
610
|
+
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.signInProviders` takes a list of the same settings with `scopes`, `tokenSignIn`, `authorizationParams`, `hidden` and `devices`, and `[]` turns them off whatever the environment says:
|
|
610
611
|
|
|
611
612
|
```ts
|
|
612
|
-
auth: {
|
|
613
|
-
auth: {
|
|
613
|
+
auth: { signInProviders: [{ issuer, clientId, clientSecret, provider: 'oidc', name: 'Acme SSO', scopes: ['groups'] }] }
|
|
614
|
+
auth: { signInProviders: [] }
|
|
614
615
|
```
|
|
615
616
|
|
|
617
|
+
### More than one provider
|
|
618
|
+
|
|
619
|
+
Each further provider takes the same variables with its number after `PROTOBASE_SIGN_IN_`, from 2 up: `PROTOBASE_SIGN_IN_2_ISSUER`, `PROTOBASE_SIGN_IN_2_CLIENT_ID`, `PROTOBASE_SIGN_IN_2_PROVIDER` and so on. The first keeps the variables without a number, so an app with one provider is configured as before. Every provider is checked on its own: a token posted under a provider's id is verified against that provider's issuer, keys and client id alone, and a [token sign-in](#token-sign-in) is kept as used by its issuer.
|
|
620
|
+
|
|
621
|
+
```sh
|
|
622
|
+
PROTOBASE_SIGN_IN_ISSUER=https://auth.example.com
|
|
623
|
+
PROTOBASE_SIGN_IN_CLIENT_ID=erp-example-com
|
|
624
|
+
PROTOBASE_SIGN_IN_CLIENT_SECRET=...
|
|
625
|
+
PROTOBASE_SIGN_IN_PROVIDER=github
|
|
626
|
+
PROTOBASE_SIGN_IN_2_ISSUER=https://id.example.com # a second provider, for token sign-in alone
|
|
627
|
+
PROTOBASE_SIGN_IN_2_PROVIDER=phone
|
|
628
|
+
PROTOBASE_SIGN_IN_2_TOKENS=true
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
- **Ids:** each provider has an id of its own; two with one id stop the app at start. A number without every number before it (a `_3_` set without a `_2_` one, or a `_2_` set without the first) stops it too, as does `_1_` or `_02_`.
|
|
632
|
+
- **Names:** `name` (`PROTOBASE_SIGN_IN_NAME`, `PROTOBASE_SIGN_IN_2_NAME`) is what people see, apart from the id, so two providers may show the same name.
|
|
633
|
+
- **Fixed authorization parameters:** `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS` (`authorizationParams` in the config), written as `name=value&other=value`, goes on every authorization request to that provider as given, such as a parameter naming which of its own sign-in methods it must use. A client cannot change or add to them: a sign-in or link with a platform provider that brings `additionalParams` of its own answers `400 AUTHORIZATION_PARAMS_FIXED`. The parameters the sign-in sets itself (`state`, `client_id`, `redirect_uri`, `response_type`, `scope`, `nonce`, `code_challenge`, `code_challenge_method`) cannot be fixed; naming one stops the app at start.
|
|
634
|
+
- **Kept off the account page:** `PROTOBASE_SIGN_IN_HIDDEN=true` (`hidden: true`) keeps people's links to that provider off the account page: the connected accounts do not list it, `/api/auth/list-accounts` leaves its links out, and connecting it, or disconnecting one of its links by its id, answers `403 PROVIDER_ACCOUNT_HIDDEN`. The link still signs in, and goes when the person is deleted. `GET /api/auth/status` marks it `hidden: true` in `platformProviders`.
|
|
635
|
+
|
|
636
|
+
### Device accounts
|
|
637
|
+
|
|
638
|
+
A provider that gives each device a subject of its own, such as one that signs in a phone app, can have every device be an account of its own: `PROTOBASE_SIGN_IN_DEVICES=true` (`devices: true`), with [token sign-in](#token-sign-in) alone, without a client secret.
|
|
639
|
+
|
|
640
|
+
- **Linked by address:** a device's first sign-in links it to the account with the address the provider vouches for, as for any provider, both addresses verified. A person holds as many of the provider's accounts as they have devices.
|
|
641
|
+
- **Its sessions:** each session a device's token sign-in starts is kept as the device's in the store's `device_session` table (auth store migration 11), which goes with the session, so it lasts as long as the session however often it is renewed. A sign-in that waits for the [second step](#two-factor-authentication) is the device's once the step is taken.
|
|
642
|
+
- **On the account page:** the **Devices** tab lists each device as the provider's name with the device's own name, which the device's ID token carries in the `device_name` claim (a string), with when it was linked, and the sessions it began under it rather than among the others. The connected accounts do not list them. `GET /api/auth/account/device-links` answers `{ links: [{ id, provider, name, device, linkedAt, sessions }] }`, `sessions` being the tokens of the sessions it began; `GET /api/auth/status` says `deviceLinks: true`.
|
|
643
|
+
- **Sign out:** **Sign out** on a device, `POST /api/auth/account/device-links/sign-out` with its `id`, refuses its subject from then on, ends every session it began, however many, in one statement in the store, and removes its link, in that order: a token for it answers `403 DEVICE_SIGNED_OUT` and never links again, by address or otherwise, and a sign-in with it that was under way ends its own session. A sign-out that stopped half way is taken again with the same `id`. The person's other devices stay signed in, and a new device of the same address links as the first ones did. The refused subjects are kept in the store's `refused_account` table (auth store migration 11), and go when the person is deleted. A [staff session](#staff-sign-in) can do neither.
|
|
644
|
+
|
|
616
645
|
### Token sign-in
|
|
617
646
|
|
|
618
647
|
A client that already holds a fresh ID token the platform's provider issued for this app, such as a phone app the person signed in to once at the provider, can post it to the app instead of sending a browser through the provider's pages. It gets the app's own session, as an emailed code or the provider's pages would give it. The provider's token counts as one factor, in the place of an emailed code: the app asks for its own second step when the person turned one on, and nothing else. Off by default:
|
|
@@ -622,15 +651,15 @@ PROTOBASE_SIGN_IN_TOKENS=true # true or false; anything else stops the ap
|
|
|
622
651
|
```
|
|
623
652
|
|
|
624
653
|
```ts
|
|
625
|
-
auth: {
|
|
654
|
+
auth: { signInProviders: [{ issuer, clientId, clientSecret, tokenSignIn: true }] }
|
|
626
655
|
```
|
|
627
656
|
|
|
628
657
|
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
658
|
|
|
630
|
-
- **Only this app's own
|
|
631
|
-
- **Alone, without a client secret:** with the issuer and `PROTOBASE_SIGN_IN_TOKENS=true` but no `PROTOBASE_SIGN_IN_CLIENT_SECRET` (`
|
|
659
|
+
- **Only this app's own providers:** the app trusts the providers it is configured with, each for its own tokens, and a token only for this app. The token must be signed with a key the provider it is posted for publishes (its discovery's `jwks_uri`) with an asymmetric algorithm, come from that provider's 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`.
|
|
660
|
+
- **Alone, without a client secret:** with the issuer and `PROTOBASE_SIGN_IN_TOKENS=true` but no `PROTOBASE_SIGN_IN_CLIENT_SECRET` (`signInProviders: [{ 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`.
|
|
632
661
|
- **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.
|
|
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.
|
|
662
|
+
- **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 [safely](#platform-sign-in-providers). Nobody is signed up (`401`), and a banned person is refused.
|
|
634
663
|
- **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.
|
|
635
664
|
- **The policy:** **Sign in with ... through the platform** in the [sign-in policy](#sign-in-policy) covers it, so Off refuses it, and so do passkeys being Required. Linking a provider with a token stays refused (`403 TOKEN_SIGN_IN_OFF`).
|
|
636
665
|
- **Rate limit:** `/api/auth/sign-in/social` takes `signInPerMinute` requests a minute per client, default 5, as a password sign-in does.
|
|
@@ -878,7 +907,7 @@ auth: { openIdProvider: { connectPage: '/-/connect', audiences: ['https://*.exam
|
|
|
878
907
|
- **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
908
|
- **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
909
|
- **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-
|
|
910
|
+
- **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-providers), through its pages or by [token sign-in](#token-sign-in).
|
|
882
911
|
- **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
912
|
|
|
884
913
|
### Registering clients
|
|
@@ -439,7 +439,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
|
|
|
439
439
|
| `PROTOBASE_SMTP_URL` | the SMTP server for password-reset mail, emailed sign-in and two-factor codes and the app's own [email](email.md), credential included: `smtp://user:password@host:587` (STARTTLS required, `?requireTLS=false` sends in plaintext, see [Email](email.md#configuration)) or `smtps://...:465`; without it they are off ([Password reset](auth.md#password-reset), [Emailed sign-in codes](auth.md#emailed-sign-in-codes)) |
|
|
440
440
|
| `PROTOBASE_MAIL_FROM` | the sender of that mail, a plain address such as `noreply@admin.example.com`; set with `PROTOBASE_SMTP_URL` or not at all |
|
|
441
441
|
| `PROTOBASE_APP_NAME` | the app's name, such as `Property Finder`: what its auth emails, its sidebar, its browser tabs and the [installed app](installable-app.md) call it, and the sender's display name of its mail, over the config's [`name`](config/app.md#name) |
|
|
442
|
-
| `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | an OpenID Connect provider people who have an account can sign in with; all three or none. `PROTOBASE_SIGN_IN_PROVIDER` and `
|
|
442
|
+
| `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | an OpenID Connect provider people who have an account can sign in with; all three or none. `PROTOBASE_SIGN_IN_PROVIDER`, `PROTOBASE_SIGN_IN_NAME`, `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS`, `PROTOBASE_SIGN_IN_HIDDEN` and `PROTOBASE_SIGN_IN_DEVICES` are optional, `PROTOBASE_SIGN_IN_TOKENS=true` turns on [token sign-in](auth.md#token-sign-in), and `PROTOBASE_SIGN_IN_2_ISSUER` and so on add more providers ([Platform sign-in providers](auth.md#platform-sign-in-providers)) |
|
|
443
443
|
| `PROTOBASE_OPERATOR_ISSUER`, `PROTOBASE_OPERATOR_CLIENT_ID`, `PROTOBASE_OPERATOR_CLIENT_SECRET` | the OpenID Connect provider of the operator's staff, for [staff sign-in](auth.md#staff-sign-in) as people of the app; all three or none. `PROTOBASE_OPERATOR_NAME` and `PROTOBASE_OPERATOR_GROUP` are optional ([Operator provider](auth.md#operator-provider)) |
|
|
444
444
|
| `PROTOBASE_ORIGINS`, `PROTOBASE_PASSKEY_DOMAIN` | the other origins the app is served on, comma separated, and the host new passkeys are made for ([Several origins](auth.md#several-origins)) |
|
|
445
445
|
| `PROTOBASE_CORS_ORIGINS` | other websites whose browser code may call the API, `*` or comma separated http and https origins ([CORS](api.md#cors)) |
|
|
@@ -573,7 +573,7 @@ protobase users disable <email> # and: enable <email>
|
|
|
573
573
|
protobase users delete <email> [--yes]
|
|
574
574
|
```
|
|
575
575
|
|
|
576
|
-
Run inside a project with sign-in on (its config's `auth`, on unless `false`, or unless the config leaves `auth` out and sets `authenticate.jwksUrl`). Like `organizations`, `token` and `auth migration`, it reads the `.env` nearest the project and needs `DATABASE_URL`. There is no web setup page, and [open sign-up](auth.md#open-sign-up), when a project turns it on, waits for the first admin: the first admin is created here. The first user is always an admin, whatever `--role` says; later users get `--role`, or the project's default role (`auth: { roles, defaultRole }` in its config). `protobase users roles` lists the roles of the project; anything else is refused with that list. `set-role` also takes comma separated roles (`sales,accountant`). `--github-id` links the new user to a GitHub user id (the number, not the login), so signing in with GitHub, the app's own provider or the [platform's](auth.md#platform-sign-in-
|
|
576
|
+
Run inside a project with sign-in on (its config's `auth`, on unless `false`, or unless the config leaves `auth` out and sets `authenticate.jwksUrl`). Like `organizations`, `token` and `auth migration`, it reads the `.env` nearest the project and needs `DATABASE_URL`. There is no web setup page, and [open sign-up](auth.md#open-sign-up), when a project turns it on, waits for the first admin: the first admin is created here. The first user is always an admin, whatever `--role` says; later users get `--role`, or the project's default role (`auth: { roles, defaultRole }` in its config). `protobase users roles` lists the roles of the project; anything else is refused with that list. `set-role` also takes comma separated roles (`sales,accountant`). `--github-id` links the new user to a GitHub user id (the number, not the login), so signing in with GitHub, the app's own provider or the [platform's](auth.md#platform-sign-in-providers), finds them whatever address GitHub reports; an id that signs in another user already is refused. `createUser(auth, { ..., accounts: [{ providerId, accountId }] })` does the same from code.
|
|
577
577
|
|
|
578
578
|
The password is typed at a hidden prompt with confirmation, read from stdin with `--password-stdin` (for scripts, e.g. `pass show erp | protobase users create me@example.com --password-stdin`), or generated with `--generate-password` and printed once; it must be 12 to 128 characters, the length the app requires of every new password. `--no-password` makes an account without one, which signs in by [emailed code](auth.md#emailed-sign-in-codes), passkey or a sign-in provider, as with an app whose [sign-in policy](auth.md#sign-in-policy) turns passwords off. A password is never accepted as an argument, since it would end up in shell history. `users list` prints email, role and creation date (and `disabled` for banned users), never credentials.
|
|
579
579
|
|
|
@@ -165,16 +165,16 @@ export default defineConfig(({ env }) => ({
|
|
|
165
165
|
}))
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
-
## auth.
|
|
168
|
+
## auth.signInProviders
|
|
169
169
|
|
|
170
|
-
- **Type:** `{ issuer: string; clientId?: string; clientSecret?: string; provider?: string; name?: string; scopes?: string[]; tokenSignIn?: boolean
|
|
171
|
-
- **Default:** the
|
|
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`
|
|
170
|
+
- **Type:** `{ issuer: string; clientId?: string; clientSecret?: string; provider?: string; name?: string; scopes?: string[]; authorizationParams?: Record<string, string>; tokenSignIn?: boolean; hidden?: boolean; devices?: boolean }[]`
|
|
171
|
+
- **Default:** the providers of the environment variables below, when set
|
|
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`, `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS` (`name=value&other=value`), `PROTOBASE_SIGN_IN_TOKENS`, `PROTOBASE_SIGN_IN_HIDDEN` and `PROTOBASE_SIGN_IN_DEVICES` (`true` or `false`); the same with `_2_`, `_3_` and so on after `PROTOBASE_SIGN_IN` for each further provider
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
The OpenID Connect providers the platform adds for people who already have an account; they never sign anyone up. Each has its own `provider` id (default `oidc`) and `name` people see; `authorizationParams` go on every authorization request to it, unchangeable by the client; `tokenSignIn: true` lets a client sign in with a fresh ID token it issued for this app ([Token sign-in](../auth.md#token-sign-in), default off); `hidden: true` keeps its links off the account page; `devices: true` makes each device an account of its own ([Devices](../auth.md#device-accounts)). `[]` turns them off whatever the environment says. One is left out when `socialProviders` has a provider with its id. Without `clientSecret` one 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 providers](../auth.md#platform-sign-in-providers).
|
|
175
175
|
|
|
176
176
|
```ts
|
|
177
|
-
export default defineConfig({ auth: {
|
|
177
|
+
export default defineConfig({ auth: { signInProviders: [] } })
|
|
178
178
|
```
|
|
179
179
|
|
|
180
180
|
## auth.operator
|