cauthy-auth 0.38.2 → 0.40.0
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 +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -235,7 +235,7 @@ npx cauthy-auth init
|
|
|
235
235
|
npx cauthy-auth init --system ledger --app-url https://app.example.com # production
|
|
236
236
|
```
|
|
237
237
|
|
|
238
|
-
The same client is your application's own identity: it manages its organizations with no person's token.
|
|
238
|
+
The same client is your application's own identity: it manages its organizations with no person's token. When people sign in with a public client (no secret) and the application's identity is a confidential client beside it, give the key that client's id: `systemKey: { privateKey, keyId, clientId }`. Its sign-ins then carry the proof that tells Cauthy which application signed the person in, and from what address. The proof also goes with the code exchange at the end of a sign-in through Cauthy's page, which a contract can require (`sign_in.require_system_proof`).
|
|
239
239
|
|
|
240
240
|
```ts
|
|
241
241
|
const org = await auth.system.organizations.create({ name: 'Acme' })
|
package/dist/index.js
CHANGED
|
@@ -1212,13 +1212,13 @@ function createCauthy(given = {}) {
|
|
|
1212
1212
|
return proto === "https" || proto === "http" ? `${proto}://${url.host}` : url.origin;
|
|
1213
1213
|
};
|
|
1214
1214
|
const attrs = (request, maxAge) => ({ secure: originOf(request).startsWith("https://"), maxAge });
|
|
1215
|
-
async function token(form) {
|
|
1215
|
+
async function token(form, proof = {}) {
|
|
1216
1216
|
const body2 = new URLSearchParams({ client_id: clientId, ...form });
|
|
1217
1217
|
if (clientSecret) body2.set("client_secret", clientSecret);
|
|
1218
1218
|
try {
|
|
1219
1219
|
const res = await doFetch(`${issuer}/v1/oauth/token`, {
|
|
1220
1220
|
method: "POST",
|
|
1221
|
-
headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json" },
|
|
1221
|
+
headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json", ...proof },
|
|
1222
1222
|
body: body2
|
|
1223
1223
|
});
|
|
1224
1224
|
if (res.ok) return { ok: true, body: await res.json() };
|
|
@@ -1458,7 +1458,7 @@ function createCauthy(given = {}) {
|
|
|
1458
1458
|
code,
|
|
1459
1459
|
redirect_uri: `${originOf(request)}${basePath}/callback`,
|
|
1460
1460
|
code_verifier: flow.verifier
|
|
1461
|
-
});
|
|
1461
|
+
}, await passedOn(request));
|
|
1462
1462
|
const s = res.ok ? await stored(res.body) : null;
|
|
1463
1463
|
if (s === null) return failed(request, "exchange_failed");
|
|
1464
1464
|
return redirect(flow.returnTo, [...await write(request, s, had), writeCookie(flowCookie, "", attrs(request, 0)), writeCookie(againCookie, "", attrs(request, 0))]);
|
|
@@ -1561,16 +1561,16 @@ function createCauthy(given = {}) {
|
|
|
1561
1561
|
return null;
|
|
1562
1562
|
}
|
|
1563
1563
|
}
|
|
1564
|
-
const clientIp = given.clientIp ?? ((request) => request.headers.get("x-forwarded-for")?.split(",").
|
|
1564
|
+
const clientIp = given.clientIp ?? ((request) => request.headers.get("x-forwarded-for")?.split(",").map((a) => a.trim()).reverse().find((a) => a !== "" && !ownNetwork(a)));
|
|
1565
1565
|
let noProofUntil = 0;
|
|
1566
1566
|
async function passedOn(request) {
|
|
1567
1567
|
if (Date.now() < noProofUntil) return {};
|
|
1568
1568
|
const ip = clientIp(request);
|
|
1569
1569
|
try {
|
|
1570
|
-
const proof = { "x-cauthy-system-token": await ownSystem.token() };
|
|
1570
|
+
const proof = { "x-cauthy-system-token": await ownSystem.token(), "x-cauthy-app-origin": originOf(request) };
|
|
1571
1571
|
return ip ? { ...proof, "x-cauthy-client-ip": ip } : proof;
|
|
1572
1572
|
} catch {
|
|
1573
|
-
noProofUntil = Date.now() +
|
|
1573
|
+
noProofUntil = Date.now() + 3e4;
|
|
1574
1574
|
return {};
|
|
1575
1575
|
}
|
|
1576
1576
|
}
|
|
@@ -2472,6 +2472,10 @@ function legalOf(raw) {
|
|
|
2472
2472
|
consentPurposes: purposes.map((p) => ({ key: String(p.key ?? ""), label: String(p.label ?? ""), required: p.required === true }))
|
|
2473
2473
|
};
|
|
2474
2474
|
}
|
|
2475
|
+
function ownNetwork(address) {
|
|
2476
|
+
const a = address.toLowerCase();
|
|
2477
|
+
return /^(127\.|10\.|192\.168\.|169\.254\.|0\.)/.test(a) || /^172\.(1[6-9]|2\d|3[01])\./.test(a) || a === "::1" || /^f[cd]/.test(a) || /^fe[89ab]/.test(a) || a.startsWith("::ffff:127.") || a === "localhost";
|
|
2478
|
+
}
|
|
2475
2479
|
|
|
2476
2480
|
// src/connect.ts
|
|
2477
2481
|
function sessionSecret() {
|