@jskit-ai/auth-provider-oidc-core 0.2.2 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-provider-oidc-core",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1"
@@ -20,7 +20,7 @@
20
20
  "openid-client": "6.8.8"
21
21
  },
22
22
  "devDependencies": {
23
- "@jskit-ai/auth-provider-local-core": "0.2.2",
23
+ "@jskit-ai/auth-provider-local-core": "0.2.3",
24
24
  "@jskit-ai/auth-web": "0.2.1",
25
25
  "oidc-provider": "9.12.2"
26
26
  },
@@ -2,7 +2,7 @@
2
2
  "private": true,
3
3
  "type": "module",
4
4
  "dependencies": {
5
- "@jskit-ai/auth-provider-oidc-core": "0.2.2",
5
+ "@jskit-ai/auth-provider-oidc-core": "0.2.3",
6
6
  "@jskit-ai/auth-web": "0.2.1"
7
7
  }
8
8
  }
@@ -119,7 +119,7 @@ function createOidcAuthService({ config, store, issuer, profileProjector = null,
119
119
  async function existingProfile(identity) {
120
120
  if (!profileProjector) return null;
121
121
  if (typeof profileProjector.findByIdentity !== "function") {
122
- throw new Error("auth.profile.projector.findByIdentity() is required for preview identity.");
122
+ throw new Error("auth.profile.projector.findByIdentity() is required for preview identity and profile lookups without sync.");
123
123
  }
124
124
  return profileProjector.findByIdentity(buildProfile(identity));
125
125
  }
@@ -273,17 +273,22 @@ function createOidcAuthService({ config, store, issuer, profileProjector = null,
273
273
  return token ? store.findActiveSessionByTokenHash(sha256(token)) : null;
274
274
  }
275
275
 
276
- async function authenticateRequest(request) {
276
+ // A dev session, or a caller that asks only who is signed in (syncProfile:
277
+ // false), reads the existing app profile instead of synchronizing it.
278
+ async function authenticateRequest(request, { syncProfile = true } = {}) {
277
279
  const session = await sessionFromRequest(request);
278
280
  if (!session) return unauthenticated(hasSessionCookie(request));
279
281
  const identity = { sub: session.sub, email: session.email, displayName: session.displayName };
280
- let result;
281
- if (session.purpose === DEV_AUTH_SESSION_PURPOSE) {
282
+ const devSession = session.purpose === DEV_AUTH_SESSION_PURPOSE;
283
+ if (devSession) {
282
284
  try {
283
285
  ensureDevAuthRuntimeAvailable(config.devAuth, request);
284
286
  } catch {
285
287
  return unauthenticated(true);
286
288
  }
289
+ }
290
+ let result;
291
+ if (devSession || !syncProfile) {
287
292
  const appProfile = await existingProfile(identity);
288
293
  if (profileProjector && !appProfile) return unauthenticated(true);
289
294
  result = buildResult(identity, { appProfile });
@@ -41,6 +41,29 @@ test("an app signs in through a self-registered client and keeps its own session
41
41
  assert.equal(signedOut.clearSession, true);
42
42
  });
43
43
 
44
+ test("authentication without profile sync reads the users row and never writes it", async (t) => {
45
+ const issuer = await startMockIssuer();
46
+ const rp = await createRelyingParty({ issuer });
47
+ t.after(async () => {
48
+ await rp.close();
49
+ await issuer.close();
50
+ });
51
+ const { input, request } = await signInAtIssuer(rp);
52
+ const result = await rp.service.oauthComplete(input, request);
53
+ const signedIn = requestAt(APP_ORIGIN, { jskit_oidc_session: result.session.token });
54
+
55
+ await rp.knex("users").update({ display_name: "Renamed in the app" });
56
+ const checked = await rp.service.authenticateRequest(signedIn, { syncProfile: false });
57
+ assert.equal(checked.authenticated, true);
58
+ assert.equal(checked.actor.appUserId, "1");
59
+ assert.equal((await rp.knex("users").first("display_name")).display_name, "Renamed in the app");
60
+
61
+ await rp.knex("users").delete();
62
+ assert.equal((await rp.service.authenticateRequest(signedIn, { syncProfile: false })).authenticated, false);
63
+ assert.equal((await rp.knex("users").count({ count: "*" }))[0].count, 0);
64
+ assert.equal((await rp.service.authenticateRequest(signedIn)).authenticated, true, "Signing in syncs the row back");
65
+ });
66
+
44
67
  test("a second sign-in reuses the origin's client and the same users row", async (t) => {
45
68
  const issuer = await startMockIssuer();
46
69
  const rp = await createRelyingParty({ issuer });