@jskit-ai/oidc-issuer-core 0.1.44 → 0.1.46
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/README.md +3 -3
- package/migrations/oidc_issuer_initial-collation.cjs +25 -0
- package/package.json +4 -4
- package/patterns/accounts-hub/PATTERN.md +2 -2
- package/patterns/accounts-hub/example/package.json +3 -3
- package/src/server/config.js +12 -12
- package/src/server/hubRoutes.js +1 -1
- package/src/server/issuer.js +1 -1
- package/src/server/oidcProvider.js +1 -1
package/README.md
CHANGED
|
@@ -20,9 +20,9 @@ The settings that matter, in the order a new hub needs them:
|
|
|
20
20
|
|---|---|
|
|
21
21
|
| `OIDC_HUB_OWNER_EMAIL` | The owner's email. That account, once confirmed, opens Apps, People and Setup. |
|
|
22
22
|
| `OIDC_HUB_REGISTRATION_TOKEN` | At least 24 random characters. Every app presents it to register. |
|
|
23
|
-
| `OIDC_HUB_SECRET` | At least 32 random bytes; required in production, never changed once set. |
|
|
24
|
-
| `APP_PUBLIC_URL` | The hub's https address, which is its issuer. Required in production. |
|
|
25
|
-
| `OIDC_HUB_EMAIL_FROM` with `RESEND_API_KEY` or `SMTP_URL` | The owner's own sender. Required in production. |
|
|
23
|
+
| `OIDC_HUB_SECRET` | At least 32 random bytes; required in staging and production, never changed once set. |
|
|
24
|
+
| `APP_PUBLIC_URL` | The hub's https address, which is its issuer. Required in staging and production. |
|
|
25
|
+
| `OIDC_HUB_EMAIL_FROM` with `RESEND_API_KEY` or `SMTP_URL` | The owner's own sender. Required in staging and production. |
|
|
26
26
|
| `OIDC_HUB_DEV_ORIGIN_PATTERNS` | Optional `https://` globs of development addresses approved automatically. |
|
|
27
27
|
|
|
28
28
|
A missing or wrong setting stops the hub with one sentence that names it.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Knex sorts this file just before oidc_issuer_initial.cjs ("-" sorts before "."), so it runs first on every
|
|
2
|
+
// database that has not run it. It runs that released migration with each table it creates in the collation of
|
|
3
|
+
// oidc_issuer_accounts, or of the next table listed that exists, instead of the database's default, and repairs a
|
|
4
|
+
// table that default left: see migrateInExistingCollation. The released migration then finds its tables in place.
|
|
5
|
+
const released = require("./oidc_issuer_initial.cjs");
|
|
6
|
+
|
|
7
|
+
exports.up = async function up(knex) {
|
|
8
|
+
const { migrateInExistingCollation } = await import("@jskit-ai/database-runtime/server/tableCollationMigrations");
|
|
9
|
+
await migrateInExistingCollation(knex, {
|
|
10
|
+
migration: "oidc_issuer_initial.cjs",
|
|
11
|
+
up: released.up,
|
|
12
|
+
tables: [
|
|
13
|
+
"oidc_issuer_accounts",
|
|
14
|
+
"oidc_issuer_models",
|
|
15
|
+
"oidc_issuer_clients",
|
|
16
|
+
"oidc_issuer_signing_keys",
|
|
17
|
+
"oidc_issuer_email_tokens",
|
|
18
|
+
"oidc_issuer_rate_limits"
|
|
19
|
+
],
|
|
20
|
+
referenceTables: ["oidc_issuer_accounts", "users", "auth_local_users"]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// The released migration's down drops its tables.
|
|
25
|
+
exports.down = async function down() {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/oidc-issuer-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -119,10 +119,10 @@
|
|
|
119
119
|
"oidc-provider": "9.12.2"
|
|
120
120
|
},
|
|
121
121
|
"devDependencies": {
|
|
122
|
-
"@jskit-ai/auth-provider-local-core": "0.2.
|
|
122
|
+
"@jskit-ai/auth-provider-local-core": "0.2.38"
|
|
123
123
|
},
|
|
124
124
|
"peerDependencies": {
|
|
125
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
126
|
-
"@jskit-ai/kernel": "0.2.
|
|
125
|
+
"@jskit-ai/database-runtime": "0.1.278",
|
|
126
|
+
"@jskit-ai/kernel": "0.2.28"
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -11,7 +11,7 @@ requires: @jskit-ai/oidc-issuer-core
|
|
|
11
11
|
## Use when
|
|
12
12
|
|
|
13
13
|
Use this pattern when one person or company owns several apps and wants one
|
|
14
|
-
account to sign in to all of them. The hub is its own project,
|
|
14
|
+
account to sign in to all of them. The hub is its own project, served on a
|
|
15
15
|
domain of its own. Apps sign in through it with
|
|
16
16
|
`@jskit-ai/auth-provider-oidc-core` (pattern `auth/oidc-sign-in`).
|
|
17
17
|
|
|
@@ -42,7 +42,7 @@ pages belong on their own origin.
|
|
|
42
42
|
self-asserted; the full address is what the owner approves.
|
|
43
43
|
- Apps receive the authorization code flow with PKCE only, no refresh tokens,
|
|
44
44
|
exact redirect URIs, and the same `sub` everywhere.
|
|
45
|
-
- The issuer and `/hub` paths are never framed; in production no hub page is.
|
|
45
|
+
- The issuer and `/hub` paths are never framed; in staging and production no hub page is.
|
|
46
46
|
(Development lets an editor's preview pane show the hub's own pages.) The
|
|
47
47
|
hub's own sign-in is first-party: apps never see passwords.
|
|
48
48
|
- Passwords use the JSKIT local-account scrypt v1 format, so local accounts
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"private": true,
|
|
3
3
|
"type": "module",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
6
|
-
"@jskit-ai/database-runtime-mysql": "0.1.
|
|
7
|
-
"@jskit-ai/oidc-issuer-core": "0.1.
|
|
5
|
+
"@jskit-ai/database-runtime": "0.1.278",
|
|
6
|
+
"@jskit-ai/database-runtime-mysql": "0.1.276",
|
|
7
|
+
"@jskit-ai/oidc-issuer-core": "0.1.46"
|
|
8
8
|
}
|
|
9
9
|
}
|
package/src/server/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { isStagingOrProduction } from "@jskit-ai/kernel/shared/support/appEnvironment";
|
|
5
5
|
|
|
6
6
|
const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
7
7
|
const MIN_SECRET_BYTES = 32;
|
|
@@ -26,10 +26,10 @@ function isLoopbackHostname(hostname) {
|
|
|
26
26
|
return LOOPBACK_HOSTS.has(host) || host.endsWith(".localhost") || /^127(?:\.\d{1,3}){3}$/u.test(host);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function resolveIssuer(env,
|
|
29
|
+
function resolveIssuer(env, stagingOrProduction) {
|
|
30
30
|
const configured = text(env.APP_PUBLIC_URL);
|
|
31
31
|
if (!configured) {
|
|
32
|
-
if (
|
|
32
|
+
if (stagingOrProduction) {
|
|
33
33
|
throw new HubConfigError("Set APP_PUBLIC_URL to your hub's https address before starting it in staging or production.");
|
|
34
34
|
}
|
|
35
35
|
const port = Number.parseInt(text(env.PORT), 10) || 3001;
|
|
@@ -64,10 +64,10 @@ function readOrCreateDevSecret(appRoot) {
|
|
|
64
64
|
return generated;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function resolveSecret(env, {
|
|
67
|
+
function resolveSecret(env, { stagingOrProduction, appRoot }) {
|
|
68
68
|
const configured = text(env.OIDC_HUB_SECRET);
|
|
69
69
|
if (!configured) {
|
|
70
|
-
if (
|
|
70
|
+
if (stagingOrProduction || !appRoot) {
|
|
71
71
|
throw new HubConfigError("Set OIDC_HUB_SECRET to a random value of at least 32 bytes.");
|
|
72
72
|
}
|
|
73
73
|
return readOrCreateDevSecret(appRoot);
|
|
@@ -100,11 +100,11 @@ function parseDevOriginPatterns(value) {
|
|
|
100
100
|
return Object.freeze(patterns);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
function resolveMail(env, {
|
|
103
|
+
function resolveMail(env, { stagingOrProduction }) {
|
|
104
104
|
const from = text(env.OIDC_HUB_EMAIL_FROM);
|
|
105
105
|
const resendApiKey = text(env.RESEND_API_KEY);
|
|
106
106
|
const smtpUrl = text(env.SMTP_URL);
|
|
107
|
-
if (
|
|
107
|
+
if (stagingOrProduction && (!from || (!resendApiKey && !smtpUrl))) {
|
|
108
108
|
throw new HubConfigError(
|
|
109
109
|
"Set OIDC_HUB_EMAIL_FROM and either RESEND_API_KEY or SMTP_URL so the hub can send confirmation and recovery emails."
|
|
110
110
|
);
|
|
@@ -143,7 +143,7 @@ function resolveHubDevAuth(env) {
|
|
|
143
143
|
* naming the variable to fix.
|
|
144
144
|
*/
|
|
145
145
|
function resolveHubConfig(env = {}, { appRoot = "" } = {}) {
|
|
146
|
-
const
|
|
146
|
+
const stagingOrProduction = isStagingOrProduction(env);
|
|
147
147
|
const registrationToken = text(env.OIDC_HUB_REGISTRATION_TOKEN);
|
|
148
148
|
if (!registrationToken) {
|
|
149
149
|
throw new HubConfigError("Set OIDC_HUB_REGISTRATION_TOKEN: apps present it when they register with the hub.");
|
|
@@ -155,18 +155,18 @@ function resolveHubConfig(env = {}, { appRoot = "" } = {}) {
|
|
|
155
155
|
if (!ownerEmail || !ownerEmail.includes("@")) {
|
|
156
156
|
throw new HubConfigError("Set OIDC_HUB_OWNER_EMAIL to the email address of the hub's owner.");
|
|
157
157
|
}
|
|
158
|
-
const issuer = resolveIssuer(env,
|
|
158
|
+
const issuer = resolveIssuer(env, stagingOrProduction);
|
|
159
159
|
return Object.freeze({
|
|
160
|
-
|
|
160
|
+
isStagingOrProduction: stagingOrProduction,
|
|
161
161
|
issuer,
|
|
162
162
|
secure: issuer.startsWith("https:"),
|
|
163
|
-
secret: resolveSecret(env, {
|
|
163
|
+
secret: resolveSecret(env, { stagingOrProduction, appRoot }),
|
|
164
164
|
secretFromEnv: Boolean(text(env.OIDC_HUB_SECRET)),
|
|
165
165
|
registrationToken,
|
|
166
166
|
ownerEmail,
|
|
167
167
|
devOriginPatterns: parseDevOriginPatterns(env.OIDC_HUB_DEV_ORIGIN_PATTERNS),
|
|
168
168
|
google: resolveGoogle(env),
|
|
169
|
-
mail: resolveMail(env, {
|
|
169
|
+
mail: resolveMail(env, { stagingOrProduction })
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
|
package/src/server/hubRoutes.js
CHANGED
|
@@ -680,7 +680,7 @@ function registerDevelopmentRoutes(app, hub, support) {
|
|
|
680
680
|
|
|
681
681
|
app.post("/hub/api/dev/login-as", async (request, reply) => {
|
|
682
682
|
const { enabled, secret } = hub.devAuth;
|
|
683
|
-
if (config.
|
|
683
|
+
if (config.isStagingOrProduction || !enabled || !secret || !isLoopbackRequest(request)) {
|
|
684
684
|
throw new HubError(404, "not_found", "Not found.");
|
|
685
685
|
}
|
|
686
686
|
if (!constantEquals(request.headers[DEV_AUTH_SECRET_HEADER], secret)) {
|
package/src/server/issuer.js
CHANGED
|
@@ -174,7 +174,7 @@ async function createOidcIssuer({
|
|
|
174
174
|
// Hub pages are never framed. Development keeps the app's own pages
|
|
175
175
|
// frameable so an editor's preview pane can show them.
|
|
176
176
|
app.addHook("onRequest", async (request, reply) => {
|
|
177
|
-
if (config.
|
|
177
|
+
if (config.isStagingOrProduction || isHubPath(request.url)) {
|
|
178
178
|
reply.raw.setHeader("x-frame-options", "DENY");
|
|
179
179
|
reply.raw.setHeader("content-security-policy", "frame-ancestors 'none'");
|
|
180
180
|
}
|
|
@@ -153,7 +153,7 @@ function createOidcProvider({ config, jwks, Adapter, accounts, clients, hasHubSe
|
|
|
153
153
|
// against private addresses, except a development hub calling an app on
|
|
154
154
|
// this same computer.
|
|
155
155
|
fetch(url, options) {
|
|
156
|
-
if (!config.
|
|
156
|
+
if (!config.isStagingOrProduction && isLoopbackHostname(new URL(url).hostname)) {
|
|
157
157
|
const { dispatcher: _dispatcher, ...direct } = options;
|
|
158
158
|
return globalThis.fetch(url, direct);
|
|
159
159
|
}
|