@jskit-ai/auth-provider-local-db-core 0.1.146 → 0.1.147
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 +4 -4
- package/src/server/lib/dbBackend.js +12 -15
- package/test/oauthStorage.test.js +3 -2
- package/test/providerRuntime.test.js +15 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-provider-local-db-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.147",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"./server/lib/index": "./src/server/lib/index.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@jskit-ai/auth-provider-local-core": "0.2.
|
|
14
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
13
|
+
"@jskit-ai/auth-provider-local-core": "0.2.6",
|
|
14
|
+
"@jskit-ai/database-runtime": "0.1.253"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@jskit-ai/kernel": "0.2.
|
|
17
|
+
"@jskit-ai/kernel": "0.2.4"
|
|
18
18
|
},
|
|
19
19
|
"description": "Database-backed local auth storage backend for JSKIT local auth.",
|
|
20
20
|
"jskit": {
|
|
@@ -168,18 +168,13 @@ function recoveryInsert(input = {}) {
|
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function createLocalDbBackend({ knex, transactionManager } = {}) {
|
|
181
|
-
assertBackendDependencies({ knex, transactionManager });
|
|
182
|
-
|
|
171
|
+
/**
|
|
172
|
+
* The `auth.local.backend` that keeps local auth's records in the database.
|
|
173
|
+
* @param {object} dependencies
|
|
174
|
+
* @param {import("@jskit-ai/database-runtime/server/types").RuntimeKnex} dependencies.knex
|
|
175
|
+
* @param {import("@jskit-ai/database-runtime/server/types").RuntimeTransactionManager} dependencies.transactionManager
|
|
176
|
+
*/
|
|
177
|
+
function createLocalDbBackend({ knex, transactionManager }) {
|
|
183
178
|
function table(client, tableName) {
|
|
184
179
|
return client(tableName);
|
|
185
180
|
}
|
|
@@ -369,11 +364,13 @@ function createLocalDbBackend({ knex, transactionManager } = {}) {
|
|
|
369
364
|
});
|
|
370
365
|
}
|
|
371
366
|
|
|
367
|
+
async function withTransaction(callback) {
|
|
368
|
+
return transactionManager.inTransaction(async (trx) => callback(createTx(trx)));
|
|
369
|
+
}
|
|
370
|
+
|
|
372
371
|
return Object.freeze({
|
|
373
372
|
tables: TABLES,
|
|
374
|
-
|
|
375
|
-
return transactionManager.inTransaction(async (trx) => callback(createTx(trx)));
|
|
376
|
-
}
|
|
373
|
+
withTransaction
|
|
377
374
|
});
|
|
378
375
|
}
|
|
379
376
|
|
|
@@ -3,6 +3,7 @@ import test from "node:test";
|
|
|
3
3
|
import createKnex from "knex";
|
|
4
4
|
import initialMigration from "../migrations/auth_local_db_initial.cjs";
|
|
5
5
|
import oauthMigration from "../migrations/auth_local_db_oauth.cjs";
|
|
6
|
+
import { noAppProfiles } from "@jskit-ai/auth-core/server/noAppProfiles";
|
|
6
7
|
import { createLocalDbBackend, LOCAL_AUTH_DB_TABLES } from "../src/server/lib/index.js";
|
|
7
8
|
import {
|
|
8
9
|
ATTEMPT_COOKIE,
|
|
@@ -30,7 +31,7 @@ test("provider sign-in and linking store identities and single-use attempts in t
|
|
|
30
31
|
const issuer = await startOidcProvider();
|
|
31
32
|
t.after(() => issuer.close());
|
|
32
33
|
const { knex, backend } = await databaseBackend(t);
|
|
33
|
-
const service = createService({ backend, oauthProviders: [oidcProviderEntry(issuer)] });
|
|
34
|
+
const service = createService({ backend, oauthProviders: [oidcProviderEntry(issuer)], profileProjector: noAppProfiles });
|
|
34
35
|
|
|
35
36
|
const { input, request } = await approveAtProvider(service);
|
|
36
37
|
assert.equal((await knex(LOCAL_AUTH_DB_TABLES.oauthAttempts).count({ count: "*" }))[0].count, 1);
|
|
@@ -87,7 +88,7 @@ test("an attempt cookie from another browser finds nothing", async (t) => {
|
|
|
87
88
|
const issuer = await startOidcProvider();
|
|
88
89
|
t.after(() => issuer.close());
|
|
89
90
|
const { backend } = await databaseBackend(t);
|
|
90
|
-
const service = createService({ backend, oauthProviders: [oidcProviderEntry(issuer)] });
|
|
91
|
+
const service = createService({ backend, oauthProviders: [oidcProviderEntry(issuer)], profileProjector: noAppProfiles });
|
|
91
92
|
const { input } = await approveAtProvider(service);
|
|
92
93
|
await assert.rejects(service.oauthComplete(input, { cookies: { [ATTEMPT_COOKIE]: "forged-browser-key" } }), {
|
|
93
94
|
code: "auth.local.oauth.expired"
|
|
@@ -7,6 +7,7 @@ import { createLocalAuthService, hashPassword } from "@jskit-ai/auth-provider-lo
|
|
|
7
7
|
import { AuthLocalProvider } from "@jskit-ai/auth-provider-local-core/server/providers/AuthLocalProvider";
|
|
8
8
|
import { createLocalDbBackend, LOCAL_AUTH_DB_TABLES } from "../src/server/lib/index.js";
|
|
9
9
|
import { AuthLocalDatabaseBackendProvider } from "../src/server/providers/AuthLocalDatabaseBackendProvider.js";
|
|
10
|
+
import { localServiceOptions } from "../../auth-provider-local-core/test-support/localService.js";
|
|
10
11
|
import packageJson from "../package.json" with { type: "json" };
|
|
11
12
|
|
|
12
13
|
const packageMetadata = packageJson.jskit;
|
|
@@ -146,20 +147,10 @@ function createDbBackendFixture() {
|
|
|
146
147
|
};
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
function createService(backend,
|
|
150
|
-
const {
|
|
151
|
-
config = {},
|
|
152
|
-
...serviceOptions
|
|
153
|
-
} = options;
|
|
150
|
+
function createService(backend, { env = {}, ...serviceOptions } = {}) {
|
|
154
151
|
return createLocalAuthService({
|
|
152
|
+
...localServiceOptions({ env }),
|
|
155
153
|
backend,
|
|
156
|
-
config: {
|
|
157
|
-
nodeEnv: "test",
|
|
158
|
-
sessionSecret: "test-secret",
|
|
159
|
-
appPublicUrl: "http://localhost:5173",
|
|
160
|
-
recoveryDevOutput: "response",
|
|
161
|
-
...config
|
|
162
|
-
},
|
|
163
154
|
...serviceOptions
|
|
164
155
|
});
|
|
165
156
|
}
|
|
@@ -284,10 +275,10 @@ test("local auth service works end to end with DB backend", async () => {
|
|
|
284
275
|
authService.writeSessionCookies(recoveryReply, recovery.session);
|
|
285
276
|
await authService.resetPassword(
|
|
286
277
|
{
|
|
287
|
-
|
|
278
|
+
password: "updated password value"
|
|
288
279
|
},
|
|
289
280
|
{
|
|
290
|
-
|
|
281
|
+
cookies: recoveryReply.cookies
|
|
291
282
|
}
|
|
292
283
|
);
|
|
293
284
|
|
|
@@ -360,20 +351,17 @@ test("local database auth uses the shared native login-as session contract", asy
|
|
|
360
351
|
password
|
|
361
352
|
}));
|
|
362
353
|
const authService = createService(backend, {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
isProduction: false,
|
|
367
|
-
secret: DEV_AUTH_SECRET
|
|
368
|
-
}
|
|
354
|
+
env: {
|
|
355
|
+
AUTH_DEV_BYPASS_ENABLED: "true",
|
|
356
|
+
AUTH_DEV_BYPASS_SECRET: DEV_AUTH_SECRET
|
|
369
357
|
}
|
|
370
358
|
});
|
|
371
359
|
|
|
372
|
-
const impersonated = await authService.devLoginAs(
|
|
373
|
-
exchange: true
|
|
374
|
-
}), {
|
|
360
|
+
const impersonated = await authService.devLoginAs({
|
|
375
361
|
email: "PREVIEW-DB@EXAMPLE.COM"
|
|
376
|
-
}
|
|
362
|
+
}, createLocalRequest({
|
|
363
|
+
exchange: true
|
|
364
|
+
}));
|
|
377
365
|
assert.equal(impersonated.actor.id, "usr_preview_db");
|
|
378
366
|
assert.equal(impersonated.session.purpose, "dev-auth");
|
|
379
367
|
|
|
@@ -446,6 +434,9 @@ test("local auth DB backend still supports lazy profile projection", async () =>
|
|
|
446
434
|
let projectionCalls = 0;
|
|
447
435
|
const authService = createService(backend, {
|
|
448
436
|
profileProjector: {
|
|
437
|
+
async findByIdentity() {
|
|
438
|
+
return null;
|
|
439
|
+
},
|
|
449
440
|
async syncIdentityProfile(profile) {
|
|
450
441
|
projectionCalls += 1;
|
|
451
442
|
return {
|