@jskit-ai/oidc-issuer-core 0.1.63 → 0.1.64

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.63",
3
+ "version": "0.1.64",
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.50"
122
+ "@jskit-ai/auth-provider-local-core": "0.2.51"
123
123
  },
124
124
  "peerDependencies": {
125
- "@jskit-ai/database-runtime": "0.1.294",
126
- "@jskit-ai/kernel": "0.2.37"
125
+ "@jskit-ai/database-runtime": "0.1.295",
126
+ "@jskit-ai/kernel": "0.2.38"
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.294",
6
- "@jskit-ai/database-runtime-mysql": "0.1.292",
7
- "@jskit-ai/oidc-issuer-core": "0.1.63"
5
+ "@jskit-ai/database-runtime": "0.1.295",
6
+ "@jskit-ai/database-runtime-mysql": "0.1.293",
7
+ "@jskit-ai/oidc-issuer-core": "0.1.64"
8
8
  }
9
9
  }
package/src/server/hub.js CHANGED
@@ -24,8 +24,10 @@ import { createSigningKeyStore } from "./signingKeys.js";
24
24
  * @param {import("./types.js").GoogleEndpoints} dependencies.googleEndpoints
25
25
  * @param {typeof fetch} dependencies.fetchImpl
26
26
  * @param {import("./types.js").HubTexts} dependencies.texts The hub's pages and emails in a person's language.
27
+ * @param {boolean} [dependencies.sharedAddress] Every client shares one address (a browser test server), so the hub
28
+ * counts no address's sign-ins or emails, only each email address's.
27
29
  */
28
- async function createHub({ knex, config, devAuth, logger, mailer, now, googleEndpoints, fetchImpl, texts }) {
30
+ async function createHub({ knex, config, devAuth, logger, mailer, now, googleEndpoints, fetchImpl, texts, sharedAddress = false }) {
29
31
  const Adapter = createKnexAdapterClass({ knex, now });
30
32
  const accounts = createAccountStore({ knex, now });
31
33
  const clients = createClientStore({ knex, now });
@@ -33,7 +35,7 @@ async function createHub({ knex, config, devAuth, logger, mailer, now, googleEnd
33
35
  const sessions = createHubSessionStore({ knex, now });
34
36
  const settings = createSettingStore({ knex });
35
37
  const emailTokens = createEmailTokenStore({ knex, now });
36
- const rateLimiter = createRateLimiter({ knex, now });
38
+ const rateLimiter = createRateLimiter({ knex, now, sharedAddress });
37
39
  const google = config.google
38
40
  ? createGoogleSignIn({ google: config.google, issuer: config.issuer, Adapter, endpoints: googleEndpoints, fetchImpl })
39
41
  : null;
@@ -1,4 +1,5 @@
1
1
  // readable-check: allow no-direct-knex - infrastructure: the OpenID provider's entry, which hands the application's Knex to the hub
2
+ import { browserTestServer } from "@jskit-ai/kernel/shared/support/appEnvironment";
2
3
  import { RegistrationError, validateRegistrationMetadata } from "./clients.js";
3
4
  import { systemClock } from "./clock.js";
4
5
  import { resolveHubConfig, resolveHubDevAuth } from "./config.js";
@@ -75,7 +76,8 @@ async function createOidcIssuer({
75
76
  now,
76
77
  googleEndpoints,
77
78
  fetchImpl,
78
- texts: createHubTexts({ appRoot, catalogs })
79
+ texts: createHubTexts({ appRoot, catalogs }),
80
+ sharedAddress: browserTestServer(env)
79
81
  });
80
82
  const { clients } = hub;
81
83
  let timer = null;
@@ -9,12 +9,15 @@ const LIMITS = Object.freeze({
9
9
  });
10
10
 
11
11
  /**
12
- * Fixed-window counters kept in the database, so limits hold across restarts.
12
+ * Fixed-window counters kept in the database, so limits hold across restarts. On a server whose clients all share one
13
+ * address (`sharedAddress`: a browser test server, which every test of its Playwright worker reaches from 127.0.0.1),
14
+ * an address is many people, so only each email address is counted.
13
15
  * @param {object} dependencies
14
16
  * @param {import("@jskit-ai/database-runtime/server/types").RuntimeKnex} dependencies.knex
15
17
  * @param {import("./types.js").HubClock} dependencies.now
18
+ * @param {boolean} [dependencies.sharedAddress]
16
19
  */
17
- function createRateLimiter({ knex, now }) {
20
+ function createRateLimiter({ knex, now, sharedAddress = false }) {
18
21
  async function hit(bucket, { limit, windowSeconds }) {
19
22
  return knex.transaction(async (trx) => {
20
23
  const current = now();
@@ -32,13 +35,13 @@ function createRateLimiter({ knex, now }) {
32
35
  });
33
36
  }
34
37
 
35
- function signIn(ip) {
36
- return hit(`sign-in:${ip}`, LIMITS.signInPerIp);
38
+ async function signIn(ip) {
39
+ return sharedAddress || hit(`sign-in:${ip}`, LIMITS.signInPerIp);
37
40
  }
38
41
 
39
42
  async function email(address, ip) {
40
43
  const perAddress = await hit(`email:${String(address).toLowerCase()}`, LIMITS.emailPerAddress);
41
- const perIp = await hit(`email-ip:${ip}`, LIMITS.emailPerIp);
44
+ const perIp = sharedAddress || await hit(`email-ip:${ip}`, LIMITS.emailPerIp);
42
45
  return perAddress && perIp;
43
46
  }
44
47