@jskit-ai/oidc-issuer-core 0.1.26 → 0.1.28
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/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.28",
|
|
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.22"
|
|
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.268",
|
|
126
|
+
"@jskit-ai/kernel": "0.2.19"
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -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.268",
|
|
6
|
+
"@jskit-ai/database-runtime-mysql": "0.1.266",
|
|
7
|
+
"@jskit-ai/oidc-issuer-core": "0.1.28"
|
|
8
8
|
}
|
|
9
9
|
}
|
package/src/server/accounts.js
CHANGED
|
@@ -102,8 +102,9 @@ function toAccount(row) {
|
|
|
102
102
|
email: row.email,
|
|
103
103
|
emailVerified: Boolean(row.email_verified),
|
|
104
104
|
displayName: row.display_name,
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
// A listed row says only whether these are set (has_password, google_linked), never what they hold.
|
|
106
|
+
hasPassword: Boolean(Object.hasOwn(row, "has_password") ? row.has_password : row.password_hash),
|
|
107
|
+
googleLinked: Boolean(Object.hasOwn(row, "google_linked") ? row.google_linked : row.google_sub),
|
|
107
108
|
disabled: Boolean(row.disabled),
|
|
108
109
|
locked: Number(row.failed_logins) >= LOCK_AFTER_FAILURES,
|
|
109
110
|
createdAt: row.created_at,
|
|
@@ -158,8 +159,17 @@ function createAccountStore({ knex, now }) {
|
|
|
158
159
|
return toAccount(await table().where({ google_sub: String(googleSub ?? "") }).first());
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
// Every account, newest first, reading only the columns an account's summary shows: never a password's hash or
|
|
163
|
+
// salt, nor the Google subject, of which it says only whether they are set.
|
|
161
164
|
async function list() {
|
|
162
|
-
|
|
165
|
+
const rows = await table()
|
|
166
|
+
.select("id", "email", "email_verified", "display_name", "disabled", "failed_logins", "created_at", "updated_at")
|
|
167
|
+
.select(
|
|
168
|
+
knex.raw("?? is not null as ??", ["password_hash", "has_password"]),
|
|
169
|
+
knex.raw("?? is not null as ??", ["google_sub", "google_linked"])
|
|
170
|
+
)
|
|
171
|
+
.orderBy("created_at", "desc");
|
|
172
|
+
return rows.map(toAccount);
|
|
163
173
|
}
|
|
164
174
|
|
|
165
175
|
async function create({ email, password = null, displayName = "", emailVerified = false, googleSub = null }) {
|
|
@@ -262,10 +272,11 @@ function createAccountStore({ knex, now }) {
|
|
|
262
272
|
return update(id, { disabled: Boolean(disabled) });
|
|
263
273
|
}
|
|
264
274
|
|
|
265
|
-
/** Imports
|
|
266
|
-
async function importLocal(
|
|
275
|
+
/** Imports exported JSKIT local accounts in one statement, keeping their ids and scrypt fields byte for byte. */
|
|
276
|
+
async function importLocal(rows) {
|
|
277
|
+
if (rows.length === 0) return;
|
|
267
278
|
const timestamp = now();
|
|
268
|
-
await table().insert({
|
|
279
|
+
await table().insert(rows.map((row) => ({
|
|
269
280
|
id: row.id,
|
|
270
281
|
email: normalizeEmail(row.email),
|
|
271
282
|
email_verified: false,
|
|
@@ -279,11 +290,12 @@ function createAccountStore({ knex, now }) {
|
|
|
279
290
|
failed_logins: 0,
|
|
280
291
|
created_at: timestamp,
|
|
281
292
|
updated_at: timestamp
|
|
282
|
-
});
|
|
293
|
+
})));
|
|
283
294
|
}
|
|
284
295
|
|
|
285
|
-
|
|
286
|
-
|
|
296
|
+
/** The stored rows whose id or email is one of these, in one read. */
|
|
297
|
+
async function rawByIdsOrEmails(ids, emails) {
|
|
298
|
+
return table().whereIn("id", ids).orWhereIn("email", emails.map(normalizeEmail));
|
|
287
299
|
}
|
|
288
300
|
|
|
289
301
|
return Object.freeze({
|
|
@@ -304,8 +316,7 @@ function createAccountStore({ knex, now }) {
|
|
|
304
316
|
// readable-check: allow setter-seam - not a slot: setDisabled changes an account's status
|
|
305
317
|
setDisabled,
|
|
306
318
|
importLocal,
|
|
307
|
-
|
|
308
|
-
rawByEmail: rowByEmail
|
|
319
|
+
rawByIdsOrEmails
|
|
309
320
|
});
|
|
310
321
|
}
|
|
311
322
|
|
package/src/server/clients.js
CHANGED
|
@@ -128,6 +128,11 @@ function createClientStore({ knex, now }) {
|
|
|
128
128
|
return table().orderBy("created_at", "desc");
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/** The ids of the apps in one of these statuses, read by status in SQL. */
|
|
132
|
+
async function listIdsWithStatus(statuses) {
|
|
133
|
+
return (await table().whereIn("status", [...statuses]).select("client_id")).map((row) => row.client_id);
|
|
134
|
+
}
|
|
135
|
+
|
|
131
136
|
/** The status a new registration from this origin receives. */
|
|
132
137
|
async function statusForOrigin(origin, devOriginPatterns) {
|
|
133
138
|
const rows = await table().where({ origin });
|
|
@@ -189,6 +194,7 @@ function createClientStore({ knex, now }) {
|
|
|
189
194
|
return Object.freeze({
|
|
190
195
|
get,
|
|
191
196
|
list,
|
|
197
|
+
listIdsWithStatus,
|
|
192
198
|
statusForOrigin,
|
|
193
199
|
insert,
|
|
194
200
|
rename,
|
package/src/server/hub.js
CHANGED
|
@@ -80,22 +80,24 @@ async function createHub({ knex, config, devAuth, logger, mailer, now, googleEnd
|
|
|
80
80
|
return kid;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Sends a signed logout token to every approved app that asked for back-channel logout, all at once: one slow app
|
|
85
|
+
* does not hold the others back.
|
|
86
|
+
*/
|
|
84
87
|
async function backchannelLogout(accountId) {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (!client?.backchannelLogoutUri) continue;
|
|
88
|
+
const provider = current.provider;
|
|
89
|
+
const results = await Promise.all((await clients.listIdsWithStatus(ACTIVE_STATUSES)).map(async (clientId) => {
|
|
90
|
+
const client = await provider.Client.find(clientId);
|
|
91
|
+
if (!client?.backchannelLogoutUri) return null;
|
|
90
92
|
try {
|
|
91
93
|
await client.backchannelLogout(accountId);
|
|
92
|
-
|
|
94
|
+
return { clientId, ok: true };
|
|
93
95
|
} catch (error) {
|
|
94
|
-
logger.warn({ clientId
|
|
95
|
-
|
|
96
|
+
logger.warn({ clientId, err: error }, "Back-channel logout was not accepted.");
|
|
97
|
+
return { clientId, ok: false };
|
|
96
98
|
}
|
|
97
|
-
}
|
|
98
|
-
return results;
|
|
99
|
+
}));
|
|
100
|
+
return results.filter(Boolean);
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
async function maintain() {
|
|
@@ -3,6 +3,8 @@ import { createAccountStore, isEmail, normalizeEmail } from "./accounts.js";
|
|
|
3
3
|
import { systemClock } from "./clock.js";
|
|
4
4
|
|
|
5
5
|
const PASSWORD_FIELDS = ["password_algorithm", "password_version", "password_salt", "password_hash"];
|
|
6
|
+
// Rows looked up and inserted per statement.
|
|
7
|
+
const ROWS_PER_STATEMENT = 500;
|
|
6
8
|
|
|
7
9
|
function parseLine(line) {
|
|
8
10
|
const value = JSON.parse(line);
|
|
@@ -43,6 +45,7 @@ async function importAccounts({ knex, text, apply = false, now = systemClock })
|
|
|
43
45
|
const accounts = createAccountStore({ knex, now });
|
|
44
46
|
const result = { imported: 0, skipped: 0, conflicts: [] };
|
|
45
47
|
const seen = new Set();
|
|
48
|
+
const candidates = [];
|
|
46
49
|
const lines = String(text).split("\n");
|
|
47
50
|
for (const [index, line] of lines.entries()) {
|
|
48
51
|
if (!line.trim()) continue;
|
|
@@ -59,23 +62,36 @@ async function importAccounts({ knex, text, apply = false, now = systemClock })
|
|
|
59
62
|
continue;
|
|
60
63
|
}
|
|
61
64
|
seen.add(row.id).add(row.email);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
candidates.push({ lineNumber, row });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (let start = 0; start < candidates.length; start += ROWS_PER_STATEMENT) {
|
|
69
|
+
const chunk = candidates.slice(start, start + ROWS_PER_STATEMENT);
|
|
70
|
+
const existing = await accounts.rawByIdsOrEmails(chunk.map(({ row }) => row.id), chunk.map(({ row }) => row.email));
|
|
71
|
+
const existingById = new Map(existing.map((account) => [account.id, account]));
|
|
72
|
+
const existingByEmail = new Map(existing.map((account) => [normalizeEmail(account.email), account]));
|
|
73
|
+
const fresh = [];
|
|
74
|
+
for (const { lineNumber, row } of chunk) {
|
|
75
|
+
const byId = existingById.get(row.id);
|
|
76
|
+
const byEmail = existingByEmail.get(row.email);
|
|
77
|
+
if (byId && byEmail && byId.id === byEmail.id && samePassword(byId, row)) {
|
|
78
|
+
result.skipped += 1;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (byId || byEmail) {
|
|
82
|
+
result.conflicts.push({
|
|
83
|
+
line: lineNumber,
|
|
84
|
+
id: row.id,
|
|
85
|
+
reason: byId ? "this id belongs to a different hub account" : "this email belongs to a different hub account"
|
|
86
|
+
});
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
fresh.push(row);
|
|
75
90
|
}
|
|
76
|
-
if (apply) await accounts.importLocal(
|
|
77
|
-
result.imported +=
|
|
91
|
+
if (apply) await accounts.importLocal(fresh);
|
|
92
|
+
result.imported += fresh.length;
|
|
78
93
|
}
|
|
94
|
+
result.conflicts.sort((left, right) => left.line - right.line);
|
|
79
95
|
return result;
|
|
80
96
|
}
|
|
81
97
|
|