@pithy-sh/auth 0.7.0 → 0.9.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 +4 -0
- package/dist/caller/certificate.d.ts +83 -0
- package/dist/caller/certificate.d.ts.map +1 -0
- package/dist/caller/certificate.js +92 -0
- package/dist/caller/request.d.ts +66 -0
- package/dist/caller/request.d.ts.map +1 -0
- package/dist/caller/request.js +71 -0
- package/dist/caller/token.d.ts +130 -0
- package/dist/caller/token.d.ts.map +1 -0
- package/dist/caller/token.js +207 -0
- package/dist/capability.d.ts +44 -1
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +7 -4
- package/dist/data/betterAuth.d.ts +1 -1
- package/dist/data/betterAuth.d.ts.map +1 -1
- package/dist/data/betterAuth.js +1 -1
- package/dist/data/tables.d.ts +1 -1
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +39 -8
- package/dist/http/credentialResign.d.ts +46 -0
- package/dist/http/credentialResign.d.ts.map +1 -0
- package/dist/http/credentialResign.js +203 -0
- package/dist/http/devLoginRoute.d.ts.map +1 -1
- package/dist/http/devLoginRoute.js +12 -5
- package/dist/http/errorCallbackUrl.d.ts.map +1 -1
- package/dist/http/errorCallbackUrl.js +15 -9
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +66 -15
- package/dist/http/providerRefusal.d.ts +8 -7
- package/dist/http/providerRefusal.d.ts.map +1 -1
- package/dist/http/providerRefusal.js +29 -32
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +18 -3
- package/dist/http/responses.d.ts +52 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +25 -1
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +60 -9
- package/dist/http/schemas.d.ts +1 -1
- package/dist/http/schemas.js +1 -1
- package/dist/instance/auth.d.ts +1225 -2
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +6 -2
- package/dist/instance/jwksReencryption.d.ts +75 -0
- package/dist/instance/jwksReencryption.d.ts.map +1 -0
- package/dist/instance/jwksReencryption.js +160 -0
- package/dist/instance/providerSignInGate.d.ts +7 -6
- package/dist/instance/providerSignInGate.d.ts.map +1 -1
- package/dist/instance/providerSignInGate.js +16 -14
- package/dist/instance/providers.d.ts.map +1 -1
- package/dist/instance/providers.js +2 -1
- package/dist/instance/secrets.d.ts +168 -1
- package/dist/instance/secrets.d.ts.map +1 -1
- package/dist/instance/secrets.js +86 -3
- package/dist/instance/sessionSecrets.d.ts +45 -0
- package/dist/instance/sessionSecrets.d.ts.map +1 -0
- package/dist/instance/sessionSecrets.js +29 -0
- package/dist/migrations/0001_init.d.ts.map +1 -1
- package/dist/migrations/0003_account_issuer_nullable.d.ts +5 -0
- package/dist/migrations/0003_account_issuer_nullable.d.ts.map +1 -0
- package/dist/migrations/0003_account_issuer_nullable.js +131 -0
- package/dist/migrations/set.d.ts +2 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +4 -2
- package/dist/seeds/devSession.d.ts.map +1 -1
- package/dist/seeds/devSession.js +2 -1
- package/dist/test-utils/liveApp.d.ts +5 -0
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +3 -3
- package/dist/test-utils/schemaDrift.d.ts +49 -0
- package/dist/test-utils/schemaDrift.d.ts.map +1 -0
- package/dist/test-utils/schemaDrift.js +35 -0
- package/dist/test-utils/scopedBackend.d.ts +183 -0
- package/dist/test-utils/scopedBackend.d.ts.map +1 -0
- package/dist/test-utils/scopedBackend.js +160 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/server-authoritative.md +182 -0
- package/package.json +14 -11
- package/src/caller/certificate.ts +133 -0
- package/src/caller/request.ts +84 -0
- package/src/caller/token.ts +276 -0
- package/src/capability.ts +65 -4
- package/src/data/betterAuth.ts +2 -1
- package/src/http/adminRoutes.ts +46 -10
- package/src/http/credentialResign.ts +268 -0
- package/src/http/devLoginRoute.ts +19 -6
- package/src/http/errorCallbackUrl.ts +21 -13
- package/src/http/middleware.ts +100 -35
- package/src/http/providerRefusal.ts +30 -32
- package/src/http/resolve.ts +27 -3
- package/src/http/responses.ts +54 -0
- package/src/http/routes.ts +97 -11
- package/src/http/schemas.ts +1 -1
- package/src/instance/auth.ts +22 -4
- package/src/instance/jwksReencryption.ts +206 -0
- package/src/instance/providerSignInGate.ts +23 -21
- package/src/instance/providers.ts +2 -1
- package/src/instance/secrets.ts +94 -1
- package/src/instance/sessionSecrets.ts +64 -0
- package/src/migrations/0001_init.ts +8 -10
- package/src/migrations/0003_account_issuer_nullable.ts +199 -0
- package/src/migrations/set.ts +3 -1
- package/src/seeds/devSession.ts +2 -1
- package/src/test-utils/liveApp.ts +8 -6
- package/src/test-utils/schemaDrift.ts +82 -0
- package/src/test-utils/scopedBackend.ts +136 -0
- package/src/version.generated.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/instance/auth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,KAAK,gBAAgB,EAAc,MAAM,aAAa,CAAC;AAGhE,OAAO,EACL,KAAK,iBAAiB,EAKvB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD,OAAO,EAAyB,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAEtF,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAEtB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/instance/auth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EA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ance/auth.js
CHANGED
|
@@ -9,6 +9,7 @@ import { refuseUnsafeProfile, sanitizeProfile } from "../profile/profile.js";
|
|
|
9
9
|
import { defaultGithubUserInfo } from "./githubUserInfo.js";
|
|
10
10
|
import { kitPlugins } from "./plugins.js";
|
|
11
11
|
import { providerUnavailable, unavailableProviderFor } from "./providers.js";
|
|
12
|
+
import { betterAuthSecrets } from "./sessionSecrets.js";
|
|
12
13
|
import { betterAuth } from "better-auth";
|
|
13
14
|
import { APIError, createAuthMiddleware } from "better-auth/api";
|
|
14
15
|
//#region src/instance/auth.ts
|
|
@@ -138,7 +139,7 @@ function makeAuth(deps) {
|
|
|
138
139
|
appName: "Pithy",
|
|
139
140
|
baseURL: deps.baseURL,
|
|
140
141
|
basePath: deps.basePath,
|
|
141
|
-
secret: deps.secret,
|
|
142
|
+
...deps.sessionSecrets === void 0 ? { secret: deps.secret } : betterAuthSecrets(deps.sessionSecrets),
|
|
142
143
|
telemetry: { enabled: false },
|
|
143
144
|
trustedOrigins: deps.trustedOrigins,
|
|
144
145
|
database: {
|
|
@@ -146,7 +147,10 @@ function makeAuth(deps) {
|
|
|
146
147
|
type: "sqlite",
|
|
147
148
|
transaction: false
|
|
148
149
|
},
|
|
149
|
-
advanced: { database: {
|
|
150
|
+
advanced: { database: {
|
|
151
|
+
generateId: () => crypto.randomUUID(),
|
|
152
|
+
validateSchema: false
|
|
153
|
+
} },
|
|
150
154
|
onAPIError: { throw: true },
|
|
151
155
|
databaseHooks: {
|
|
152
156
|
user: {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
4
|
+
import type { Logger } from "@pithy-sh/core/src/logger/logger";
|
|
5
|
+
import type { AuthDatabase } from "../data/tables";
|
|
6
|
+
import { type SessionSecretVersions } from "./sessionSecrets";
|
|
7
|
+
/**
|
|
8
|
+
* **The JWKS private keys, moved under the session secret's newest version before the old one retires (#602).**
|
|
9
|
+
*
|
|
10
|
+
* Better Auth seals every key in `pithy_auth_jwks` under the session secret (`plugins/jwt/utils.mjs`), and a
|
|
11
|
+
* key has no expiry that would make it safe to stop being able to open it. An unattended rotation of
|
|
12
|
+
* `auth-session-secret` therefore waits, before it retires the previous version, for this Worker to say the
|
|
13
|
+
* keys have moved — the secret's registry entry names them as `auth-jwks` — and this is where they move.
|
|
14
|
+
*
|
|
15
|
+
* Each key is opened under whichever retained version it names (`$ba$<version>$…`), or — for one sealed
|
|
16
|
+
* before the kit handed Better Auth a version set, which carries no envelope — under each retained version
|
|
17
|
+
* in turn, oldest first. It is sealed again under the current version and written back only if the row
|
|
18
|
+
* still holds what was read, so two isolates moving the same key cannot interleave into a value neither
|
|
19
|
+
* wrote. Then the move is recorded in the secrets D1, where the manager reads it.
|
|
20
|
+
*
|
|
21
|
+
* **It never makes a key unopenable.** A key no retained version opens is left exactly as it is and
|
|
22
|
+
* counted; it was already lost, and nothing here can lose it further. It does not hold the record back,
|
|
23
|
+
* because waiting cannot make it open — and a retirement held forever over a key that will never be used
|
|
24
|
+
* is an envelope that grows on every rotation.
|
|
25
|
+
*/
|
|
26
|
+
/** What one pass did, in counts. */
|
|
27
|
+
export interface JwksReencryption {
|
|
28
|
+
/** Keys sealed again under the current version. */
|
|
29
|
+
moved: number;
|
|
30
|
+
/** Keys already under it. */
|
|
31
|
+
current: number;
|
|
32
|
+
/** Keys no retained version opens. Left as they were. */
|
|
33
|
+
unopenable: number;
|
|
34
|
+
}
|
|
35
|
+
/** Move every JWKS private key under the current version of the session secret. */
|
|
36
|
+
export declare function reencryptJwks(db: AuthDatabase, versions: SessionSecretVersions): Promise<JwksReencryption>;
|
|
37
|
+
/** Forget what this isolate has settled or is waiting on. For tests. */
|
|
38
|
+
export declare function resetJwksReencryption(): void;
|
|
39
|
+
/** What {@link ensureJwksSealedUnderCurrent} needs. */
|
|
40
|
+
export interface EnsureJwksDeps {
|
|
41
|
+
/** The application database the JWKS keys live in. */
|
|
42
|
+
db: AuthDatabase;
|
|
43
|
+
/**
|
|
44
|
+
* That database's binding name — `auth({ database })`. The holder the move is recorded under, so two auth
|
|
45
|
+
* Workers over two databases are waited for one by one rather than one answering for both.
|
|
46
|
+
*/
|
|
47
|
+
holder: string;
|
|
48
|
+
/** The secrets D1 the move is recorded in. */
|
|
49
|
+
secrets: D1Database;
|
|
50
|
+
/** The session secret's retained versions, as this request resolved them. */
|
|
51
|
+
versions: SessionSecretVersions;
|
|
52
|
+
/** Where a failure is said. Never fatal. */
|
|
53
|
+
log: Logger;
|
|
54
|
+
/** The clock. Defaults to now. */
|
|
55
|
+
now?: Date;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Make sure the JWKS keys are sealed under the current version, and that the secrets D1 says so — once per
|
|
59
|
+
* version per isolate.
|
|
60
|
+
*
|
|
61
|
+
* **Recorded with one version too.** While the secret holds one version there is nothing to move, and the
|
|
62
|
+
* record says the keys are under it ({@link recordSoleVersion}). That is how the manager knows this database
|
|
63
|
+
* holds keys before the first rotation: a holder it has never heard from is one it cannot wait for.
|
|
64
|
+
*
|
|
65
|
+
* **Not on the first request that sees the version.** Another isolate may still hold the envelope it cached
|
|
66
|
+
* before the append, with no key for the new version; a key re-sealed under it now would fail there. So the
|
|
67
|
+
* first sight is recorded, and the move waits until every cache filled before it has expired
|
|
68
|
+
* (`claimReencryption`, `REENCRYPTION_SETTLE_MS`). An isolate told to wait does not ask again until then.
|
|
69
|
+
*
|
|
70
|
+
* **Never fatal.** It runs on a request, and the request it rides on is somebody signing in; a failure here
|
|
71
|
+
* leaves the keys where they were — still opening, since the previous version is still held — and the
|
|
72
|
+
* retirement waiting. The next isolate tries again.
|
|
73
|
+
*/
|
|
74
|
+
export declare function ensureJwksSealedUnderCurrent(deps: EnsureJwksDeps): Promise<void>;
|
|
75
|
+
//# sourceMappingURL=jwksReencryption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwksReencryption.d.ts","sourceRoot":"","sources":["../../src/instance/jwksReencryption.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAS/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAqB,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEjF;;;;;;;;;;;;;;;;;;GAkBG;AAEH,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;CACpB;AAyBD,mFAAmF;AACnF,wBAAsB,aAAa,CAAC,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAmChH;AAWD,wEAAwE;AACxE,wBAAgB,qBAAqB,IAAI,IAAI,CAG5C;AAED,uDAAuD;AACvD,MAAM,WAAW,cAAc;IAC7B,sDAAsD;IACtD,EAAE,EAAE,YAAY,CAAC;IACjB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,OAAO,EAAE,UAAU,CAAC;IACpB,6EAA6E;IAC7E,QAAQ,EAAE,qBAAqB,CAAC;IAChC,4CAA4C;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CA6CtF"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { AUTH_JWKS_DEPENDENT, AUTH_SESSION_SECRET } from "./secrets.js";
|
|
4
|
+
import { betterAuthSecrets } from "./sessionSecrets.js";
|
|
5
|
+
import { createDatabase } from "@pithy-sh/core/src/data/db";
|
|
6
|
+
import { secretsTables } from "@pithy-sh/secrets/src/data/tables";
|
|
7
|
+
import { claimReencryption, currentSealedVersion, recordReencryption, recordSoleVersion } from "@pithy-sh/secrets/src/rotation/reencryption";
|
|
8
|
+
import { parseEnvelope, symmetricDecrypt, symmetricEncrypt } from "better-auth/crypto";
|
|
9
|
+
//#region src/instance/jwksReencryption.ts
|
|
10
|
+
/** Better Auth's own key structure for a version set, built the way `buildSecretConfig` builds it. */
|
|
11
|
+
function secretConfig(versions) {
|
|
12
|
+
const { secrets } = betterAuthSecrets(versions);
|
|
13
|
+
return {
|
|
14
|
+
keys: new Map(secrets.map((one) => [one.version, one.value])),
|
|
15
|
+
currentVersion: Number(versions.currentVersion)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** Open one stored private key, or `null` when no retained version opens it. */
|
|
19
|
+
async function opened(stored, versions, config) {
|
|
20
|
+
if (parseEnvelope(stored) !== null) return await symmetricDecrypt({
|
|
21
|
+
key: config,
|
|
22
|
+
data: stored
|
|
23
|
+
}).catch(() => null);
|
|
24
|
+
const oldestFirst = [...betterAuthSecrets(versions).secrets].sort((left, right) => left.version - right.version);
|
|
25
|
+
for (const candidate of oldestFirst) {
|
|
26
|
+
const plain = await symmetricDecrypt({
|
|
27
|
+
key: candidate.value,
|
|
28
|
+
data: stored
|
|
29
|
+
}).catch(() => null);
|
|
30
|
+
if (plain !== null) return plain;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
/** Move every JWKS private key under the current version of the session secret. */
|
|
35
|
+
async function reencryptJwks(db, versions) {
|
|
36
|
+
const config = secretConfig(versions);
|
|
37
|
+
const current = Number(versions.currentVersion);
|
|
38
|
+
const result = {
|
|
39
|
+
moved: 0,
|
|
40
|
+
current: 0,
|
|
41
|
+
unopenable: 0
|
|
42
|
+
};
|
|
43
|
+
const rows = await db.selectFrom("pithyAuthJwks").select(["id", "privateKey"]).execute();
|
|
44
|
+
for (const row of rows) {
|
|
45
|
+
let stored;
|
|
46
|
+
try {
|
|
47
|
+
stored = JSON.parse(row.privateKey);
|
|
48
|
+
} catch {
|
|
49
|
+
stored = void 0;
|
|
50
|
+
}
|
|
51
|
+
if (typeof stored !== "string") {
|
|
52
|
+
result.unopenable += 1;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (parseEnvelope(stored)?.version === current) {
|
|
56
|
+
result.current += 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const plain = await opened(stored, versions, config);
|
|
60
|
+
if (plain === null) {
|
|
61
|
+
result.unopenable += 1;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const sealed = JSON.stringify(await symmetricEncrypt({
|
|
65
|
+
key: config,
|
|
66
|
+
data: plain
|
|
67
|
+
}));
|
|
68
|
+
await db.updateTable("pithyAuthJwks").set({ privateKey: sealed }).where("id", "=", row.id).where("privateKey", "=", row.privateKey).execute();
|
|
69
|
+
result.moved += 1;
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The versions this isolate has finished with — moved, or failed to — keyed by version and fingerprint, so a
|
|
75
|
+
* version key reused after an `update` is a new version here too.
|
|
76
|
+
*/
|
|
77
|
+
const settled = /* @__PURE__ */ new Set();
|
|
78
|
+
/** The versions this isolate was told to wait on, with when to ask again. */
|
|
79
|
+
const waiting = /* @__PURE__ */ new Map();
|
|
80
|
+
/** Forget what this isolate has settled or is waiting on. For tests. */
|
|
81
|
+
function resetJwksReencryption() {
|
|
82
|
+
settled.clear();
|
|
83
|
+
waiting.clear();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Make sure the JWKS keys are sealed under the current version, and that the secrets D1 says so — once per
|
|
87
|
+
* version per isolate.
|
|
88
|
+
*
|
|
89
|
+
* **Recorded with one version too.** While the secret holds one version there is nothing to move, and the
|
|
90
|
+
* record says the keys are under it ({@link recordSoleVersion}). That is how the manager knows this database
|
|
91
|
+
* holds keys before the first rotation: a holder it has never heard from is one it cannot wait for.
|
|
92
|
+
*
|
|
93
|
+
* **Not on the first request that sees the version.** Another isolate may still hold the envelope it cached
|
|
94
|
+
* before the append, with no key for the new version; a key re-sealed under it now would fail there. So the
|
|
95
|
+
* first sight is recorded, and the move waits until every cache filled before it has expired
|
|
96
|
+
* (`claimReencryption`, `REENCRYPTION_SETTLE_MS`). An isolate told to wait does not ask again until then.
|
|
97
|
+
*
|
|
98
|
+
* **Never fatal.** It runs on a request, and the request it rides on is somebody signing in; a failure here
|
|
99
|
+
* leaves the keys where they were — still opening, since the previous version is still held — and the
|
|
100
|
+
* retirement waiting. The next isolate tries again.
|
|
101
|
+
*/
|
|
102
|
+
async function ensureJwksSealedUnderCurrent(deps) {
|
|
103
|
+
const { versions } = deps;
|
|
104
|
+
const sole = Object.keys(versions.versions).length < 2;
|
|
105
|
+
const now = deps.now ?? /* @__PURE__ */ new Date();
|
|
106
|
+
try {
|
|
107
|
+
const sealed = await currentSealedVersion(versions);
|
|
108
|
+
const key = `${deps.holder}:${sole ? "sole" : "rotating"}:${sealed.version}:${sealed.fingerprint}`;
|
|
109
|
+
if (settled.has(key) || (waiting.get(key) ?? 0) > now.getTime()) return;
|
|
110
|
+
try {
|
|
111
|
+
const secretsDb = createDatabase(deps.secrets, secretsTables);
|
|
112
|
+
const where = {
|
|
113
|
+
name: AUTH_SESSION_SECRET,
|
|
114
|
+
dependent: AUTH_JWKS_DEPENDENT,
|
|
115
|
+
holder: deps.holder
|
|
116
|
+
};
|
|
117
|
+
if (sole) {
|
|
118
|
+
settled.add(key);
|
|
119
|
+
await recordSoleVersion(secretsDb, {
|
|
120
|
+
...where,
|
|
121
|
+
sealed,
|
|
122
|
+
now
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const claim = await claimReencryption(secretsDb, {
|
|
127
|
+
...where,
|
|
128
|
+
sealed,
|
|
129
|
+
now
|
|
130
|
+
});
|
|
131
|
+
if (claim.state === "moved") {
|
|
132
|
+
settled.add(key);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (claim.state === "settling") {
|
|
136
|
+
waiting.set(key, claim.until.getTime());
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
settled.add(key);
|
|
140
|
+
const moved = await reencryptJwks(deps.db, versions);
|
|
141
|
+
await recordReencryption(secretsDb, {
|
|
142
|
+
...where,
|
|
143
|
+
...sealed,
|
|
144
|
+
now
|
|
145
|
+
});
|
|
146
|
+
deps.log.info("jwks re-encrypted under the current session secret", {
|
|
147
|
+
version: sealed.version,
|
|
148
|
+
...moved
|
|
149
|
+
});
|
|
150
|
+
if (moved.unopenable > 0) deps.log.warn("jwks keys no retained session secret opens were left as they were", { unopenable: moved.unopenable });
|
|
151
|
+
} catch (error) {
|
|
152
|
+
settled.add(key);
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
deps.log.warn("jwks re-encryption did not finish; the previous session secret stays until it does", { reason: error instanceof Error ? error.message : String(error) });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
export { ensureJwksSealedUnderCurrent, reencryptJwks, resetJwksReencryption };
|
|
@@ -20,9 +20,10 @@ import type { BetterAuthPlugin } from "better-auth";
|
|
|
20
20
|
* The mitigating fact is that it requires a provider-signed, audience-bound assertion of the address,
|
|
21
21
|
* so it is not an address an attacker picks — which is why the claim above says *the redirect
|
|
22
22
|
* callback* and not *provider sign-in*.
|
|
23
|
-
* - **A plugin that calls `handleOAuthUserInfo`
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* - **A plugin that calls `handleOAuthUserInfo` outside the redirect callback.** `plugins/one-tap/index.mjs:64`
|
|
24
|
+
* resolves a verified Google id token through Google's own `getUserInfo` with no OAuth state, which
|
|
25
|
+
* this gate passes through, or builds the user info itself when Google is not configured;
|
|
26
|
+
* `plugins/oauth-proxy/index.mjs:127` lifts it out of an encrypted proxy payload. The kit composes
|
|
26
27
|
* neither. `./refusalTransport` is where a composed plugin is ruled on.
|
|
27
28
|
* - **An adopter plugin that replaces `ctx.socialProviders` in its own `init`.** Kit plugins run first
|
|
28
29
|
* by contract (`./auth.ts` composes them ahead of the adopter's), so the wrap is installed before
|
|
@@ -42,8 +43,8 @@ import type { BetterAuthPlugin } from "better-auth";
|
|
|
42
43
|
* | 4 | Not attached, no account at that address | Refused |
|
|
43
44
|
*
|
|
44
45
|
* Rows 3 and 4 differ only in whether a row exists at an address **the caller chose**, and Better Auth
|
|
45
|
-
* answers them with two different codes — `account_not_linked` (`oauth2/link-account.mjs:
|
|
46
|
-
* only inside `if (dbUser)`) and `signup_disabled` (`:
|
|
46
|
+
* answers them with two different codes — `account_not_linked` (`oauth2/link-account.mjs:142`, returned
|
|
47
|
+
* only inside `if (dbUser)`) and `signup_disabled` (`:257`, the `else` of that same branch). Both reach
|
|
47
48
|
* the browser as `?error=<code>`. That is an account-enumeration oracle needing one provider account,
|
|
48
49
|
* none on the target, and no page render.
|
|
49
50
|
*
|
|
@@ -53,7 +54,7 @@ import type { BetterAuthPlugin } from "better-auth";
|
|
|
53
54
|
* another, and the last keyed on a value `callbackURL` supplies, so it rewrote *successful* sign-ins.
|
|
54
55
|
* By the time a response exists the fact that distinguished the two cases is gone and what is left is
|
|
55
56
|
* partly the caller's. `getUserInfo` is the last seam that holds the fact itself: `callback.mjs:120`
|
|
56
|
-
* calls it, `:
|
|
57
|
+
* calls it, `:172` calls `handleOAuthUserInfo`, and **nothing between them reads a user row** — so a refusal thrown
|
|
57
58
|
* here means neither of those two lines is ever reached and there is no pair left to collapse.
|
|
58
59
|
*
|
|
59
60
|
* ## Why a wrapper, and not a `getUserInfo` supplied in the config block
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providerSignInGate.d.ts","sourceRoot":"","sources":["../../src/instance/providerSignInGate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAe,gBAAgB,EAAiB,MAAM,aAAa,CAAC;AAKhF
|
|
1
|
+
{"version":3,"file":"providerSignInGate.d.ts","sourceRoot":"","sources":["../../src/instance/providerSignInGate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAe,gBAAgB,EAAiB,MAAM,aAAa,CAAC;AAKhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,gCAAgC,CAAC;AAEtE;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC;IAC3C,wGAAwG;aACxG,aAAa,EAAE,kCAAkC;IACjD,8EAA8E;aAC9E,SAAS,EAAE,8BAA8B;CACjC,CAAC;AAEX,2GAA2G;AAC3G,MAAM,WAAW,sBAAsB;IACrC,kGAAkG;IAClG,IAAI,EAAE,SAAS,CAAC;IAChB;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B;AA0KD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,gBAAgB,CAkBjF"}
|
|
@@ -22,9 +22,10 @@ import { APIError, getOAuthState } from "better-auth/api";
|
|
|
22
22
|
* The mitigating fact is that it requires a provider-signed, audience-bound assertion of the address,
|
|
23
23
|
* so it is not an address an attacker picks — which is why the claim above says *the redirect
|
|
24
24
|
* callback* and not *provider sign-in*.
|
|
25
|
-
* - **A plugin that calls `handleOAuthUserInfo`
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* - **A plugin that calls `handleOAuthUserInfo` outside the redirect callback.** `plugins/one-tap/index.mjs:64`
|
|
26
|
+
* resolves a verified Google id token through Google's own `getUserInfo` with no OAuth state, which
|
|
27
|
+
* this gate passes through, or builds the user info itself when Google is not configured;
|
|
28
|
+
* `plugins/oauth-proxy/index.mjs:127` lifts it out of an encrypted proxy payload. The kit composes
|
|
28
29
|
* neither. `./refusalTransport` is where a composed plugin is ruled on.
|
|
29
30
|
* - **An adopter plugin that replaces `ctx.socialProviders` in its own `init`.** Kit plugins run first
|
|
30
31
|
* by contract (`./auth.ts` composes them ahead of the adopter's), so the wrap is installed before
|
|
@@ -44,8 +45,8 @@ import { APIError, getOAuthState } from "better-auth/api";
|
|
|
44
45
|
* | 4 | Not attached, no account at that address | Refused |
|
|
45
46
|
*
|
|
46
47
|
* Rows 3 and 4 differ only in whether a row exists at an address **the caller chose**, and Better Auth
|
|
47
|
-
* answers them with two different codes — `account_not_linked` (`oauth2/link-account.mjs:
|
|
48
|
-
* only inside `if (dbUser)`) and `signup_disabled` (`:
|
|
48
|
+
* answers them with two different codes — `account_not_linked` (`oauth2/link-account.mjs:142`, returned
|
|
49
|
+
* only inside `if (dbUser)`) and `signup_disabled` (`:257`, the `else` of that same branch). Both reach
|
|
49
50
|
* the browser as `?error=<code>`. That is an account-enumeration oracle needing one provider account,
|
|
50
51
|
* none on the target, and no page render.
|
|
51
52
|
*
|
|
@@ -55,7 +56,7 @@ import { APIError, getOAuthState } from "better-auth/api";
|
|
|
55
56
|
* another, and the last keyed on a value `callbackURL` supplies, so it rewrote *successful* sign-ins.
|
|
56
57
|
* By the time a response exists the fact that distinguished the two cases is gone and what is left is
|
|
57
58
|
* partly the caller's. `getUserInfo` is the last seam that holds the fact itself: `callback.mjs:120`
|
|
58
|
-
* calls it, `:
|
|
59
|
+
* calls it, `:172` calls `handleOAuthUserInfo`, and **nothing between them reads a user row** — so a refusal thrown
|
|
59
60
|
* here means neither of those two lines is ever reached and there is no pair left to collapse.
|
|
60
61
|
*
|
|
61
62
|
* ## Why a wrapper, and not a `getUserInfo` supplied in the config block
|
|
@@ -103,8 +104,8 @@ const PROVIDER_SIGN_IN_REFUSAL_REASONS = {
|
|
|
103
104
|
* than asserted:** `providerSignInGate.workers.test.ts` drives a refusal the dependency still emits
|
|
104
105
|
* (`email_not_found`) beside one this gate emits and requires the two `Location` headers to differ in
|
|
105
106
|
* nothing but the code. `ctx.redirect(url)` is itself only `new APIError("FOUND", undefined, headers)`
|
|
106
|
-
* with `location` set (`better-call/dist/context.mjs:
|
|
107
|
-
* straight through its `onError` to `toResponse` (`api/index.mjs:
|
|
107
|
+
* with `location` set (`better-call/dist/context.mjs:62`), and better-auth's router passes a `FOUND`
|
|
108
|
+
* straight through its `onError` to `toResponse` (`api/index.mjs:196`), so this is the same object the
|
|
108
109
|
* dependency would have thrown — built without the endpoint context `getUserInfo` is not handed.
|
|
109
110
|
*
|
|
110
111
|
* The value being appended to is the OAuth state's own `errorURL`, which is where `redirectOnError`
|
|
@@ -132,12 +133,13 @@ function refusalWithoutRedirect() {
|
|
|
132
133
|
/**
|
|
133
134
|
* Is this provider identity already attached to some account here? Row 1.
|
|
134
135
|
*
|
|
135
|
-
* **Keyed on `(providerId, accountId)`, which is
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* which is
|
|
136
|
+
* **Keyed on `(providerId, accountId)`, which is Better Auth's own account key.** 1.7.0–1.7.2 keyed an
|
|
137
|
+
* account on `(issuer, accountId)` instead, and this gate read the wider pair rather than copy how Better
|
|
138
|
+
* Auth derived an issuer. 1.7.3 reverted to the 1.6 model (better-auth/better-auth#11153), and the lookup
|
|
139
|
+
* the callback makes is now `findAccountOwnerByKey({ providerId, accountId })` (`link-account.mjs:80`), so
|
|
140
|
+
* the two ask the same question of the same columns (#787). A false match here would pass the attempt
|
|
141
|
+
* through and let Better Auth decide, which is the safe direction; a false *miss* is what would be
|
|
142
|
+
* dangerous, and an identical key cannot cause one.
|
|
141
143
|
*
|
|
142
144
|
* It reads no address and no verified flag, which is what keeps an `allowDifferentEmails` link signing in.
|
|
143
145
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/instance/providers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/instance/providers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAEjE,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,WAAW,CAAC;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,gBAAgB,CAAC,WAAW,IACpC;IAAE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAA;CAAE,GAC9D;IAAE,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;CAAE,CAAC;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAA0B,CAAC;AAEvF,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,YAAI,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAC;AAEtF,yCAAyC;AACzC,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,0FAA0F;IAC1F,MAAM,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACjD,0FAA0F;IAC1F,KAAK,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAC/C,4FAA4F;IAC5F,QAAQ,EAAE,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;IACrD,0FAA0F;IAC1F,MAAM,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;CAClD;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,iBAAiB,CAK3D,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,WAAW,EAC/C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,GAC/B,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAOxC;AAyBD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,SAAS,EAAE,iBAAiB,GAC3B,gBAAgB,GAAG,SAAS,CAO9B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,UAAU,CAQ1E"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { PithyError } from "@pithy-sh/core/src/error/pithyError";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
+
import { pithyCommand } from "@pithy-sh/core/src/cli/command";
|
|
5
6
|
//#region src/instance/providers.ts
|
|
6
7
|
/**
|
|
7
8
|
* The one `disabled` value, so the state has one spelling.
|
|
@@ -105,7 +106,7 @@ function providerUnavailable(provider) {
|
|
|
105
106
|
code: "auth/provider_unavailable",
|
|
106
107
|
status: 503,
|
|
107
108
|
message: `Signing in with ${provider} is unavailable right now. Use a magic link instead.`,
|
|
108
|
-
action: `Provision \`auth-${provider}-credentials\` for this environment with
|
|
109
|
+
action: `Provision \`auth-${provider}-credentials\` for this environment with \`${pithyCommand("secrets create", { args: [`auth-${provider}-credentials`] })}\`, or set \`${provider}.enabled\` to false in pithy.config.ts.`,
|
|
109
110
|
detail: `provider ${provider} is enabled and its credential could not be resolved; the instance was built without it`
|
|
110
111
|
});
|
|
111
112
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import type { SecretsStoreEnv } from "@pithy-sh/secrets/src/env/bindings";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
+
import type { SessionSecretVersions } from "./sessionSecrets";
|
|
5
6
|
/**
|
|
6
7
|
* The secrets `@pithy-sh/auth` reads, declared as a minimal registry. The secret name is the join key:
|
|
7
8
|
* `secretsStore` resolves the same encrypted D1 row regardless of which capability's registry names it,
|
|
@@ -26,6 +27,33 @@ export declare const AUTH_GOOGLE_CREDENTIALS = "auth-google-credentials";
|
|
|
26
27
|
export declare const AUTH_APPLE_CREDENTIALS = "auth-apple-credentials";
|
|
27
28
|
export declare const AUTH_FACEBOOK_CREDENTIALS = "auth-facebook-credentials";
|
|
28
29
|
export declare const AUTH_GITHUB_CREDENTIALS = "auth-github-credentials";
|
|
30
|
+
/**
|
|
31
|
+
* The JWKS private keys, as `auth-session-secret`'s overlap names them (#602).
|
|
32
|
+
*
|
|
33
|
+
* Better Auth encrypts every key in `pithy_auth_jwks` under the session secret, and a key never expires —
|
|
34
|
+
* so retiring the version one is sealed under would leave a signing key nothing can open. The session
|
|
35
|
+
* secret's registry entry names this dependent, `instance/jwksReencryption.ts` moves the keys under the
|
|
36
|
+
* newest version and records it, and the secrets manager retires nothing until it has.
|
|
37
|
+
*/
|
|
38
|
+
export declare const AUTH_JWKS_DEPENDENT = "auth-jwks";
|
|
39
|
+
/**
|
|
40
|
+
* The Better Auth plugins that seal rows of their own under the session secret, by id.
|
|
41
|
+
*
|
|
42
|
+
* `two-factor` seals every TOTP secret with `symmetricEncrypt({ key: ctx.context.secretConfig })`, and its
|
|
43
|
+
* backup codes the same way under `storeBackupCodes: "encrypted"` (`plugins/two-factor/index.mjs`,
|
|
44
|
+
* `backup-codes/index.mjs`). Neither expires. Nothing in the kit re-encrypts them, so an unattended rotation
|
|
45
|
+
* beside one is refused at `auth()` rather than allowed to retire the version they are sealed under.
|
|
46
|
+
*/
|
|
47
|
+
export declare const SESSION_SECRET_SEALING_PLUGINS: readonly string[];
|
|
48
|
+
/**
|
|
49
|
+
* How many days a replaced session secret keeps verifying: the session's own lifetime, rounded up.
|
|
50
|
+
*
|
|
51
|
+
* **That is the whole of the overlap's argument.** A session in use is re-signed on its next request
|
|
52
|
+
* (`http/credentialResign.ts`), and its expiry slides forward on use — so a session that goes the whole
|
|
53
|
+
* overlap without one request has expired by the time the overlap ends. Any shorter, and a session used
|
|
54
|
+
* yesterday is signed out when the old version retires.
|
|
55
|
+
*/
|
|
56
|
+
export declare function sessionSecretOverlapDays(sessionExpiresIn: number): number;
|
|
29
57
|
/** The Google OAuth credential pair, stored as one typed JSON secret. */
|
|
30
58
|
export declare const GoogleOAuthCredentials: z.ZodObject<{
|
|
31
59
|
clientId: z.ZodString;
|
|
@@ -69,7 +97,116 @@ export declare const authSecretsRegistry: {
|
|
|
69
97
|
readonly rotation: {
|
|
70
98
|
readonly kind: "local";
|
|
71
99
|
};
|
|
100
|
+
readonly overlap: {
|
|
101
|
+
readonly days: 7;
|
|
102
|
+
readonly minimumDays: 7;
|
|
103
|
+
readonly reencrypt: readonly ["auth-jwks"];
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
readonly "auth-google-credentials": {
|
|
107
|
+
readonly backend: "d1";
|
|
108
|
+
readonly scope: "environment";
|
|
109
|
+
readonly rotatable: false;
|
|
110
|
+
readonly valueType: "json";
|
|
111
|
+
readonly schema: z.ZodObject<{
|
|
112
|
+
clientId: z.ZodString;
|
|
113
|
+
clientSecret: z.ZodString;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
readonly origin: {
|
|
116
|
+
readonly kind: "obtained";
|
|
117
|
+
readonly issuer: "google";
|
|
118
|
+
readonly documentation: "https://console.cloud.google.com/apis/credentials";
|
|
119
|
+
};
|
|
120
|
+
readonly rotation: {
|
|
121
|
+
readonly kind: "manual";
|
|
122
|
+
readonly issuer: "google";
|
|
123
|
+
readonly documentation: "https://console.cloud.google.com/apis/credentials";
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
readonly "auth-apple-credentials": {
|
|
127
|
+
readonly backend: "d1";
|
|
128
|
+
readonly scope: "environment";
|
|
129
|
+
readonly rotatable: true;
|
|
130
|
+
readonly valueType: "json";
|
|
131
|
+
readonly schema: z.ZodObject<{
|
|
132
|
+
clientId: z.ZodString;
|
|
133
|
+
clientSecret: z.ZodString;
|
|
134
|
+
appBundleIdentifier: z.ZodOptional<z.ZodString>;
|
|
135
|
+
}, z.core.$strip>;
|
|
136
|
+
readonly origin: {
|
|
137
|
+
readonly kind: "obtained";
|
|
138
|
+
readonly issuer: "apple";
|
|
139
|
+
readonly documentation: "https://developer.apple.com/account/resources/authkeys/list";
|
|
140
|
+
};
|
|
141
|
+
readonly rotation: {
|
|
142
|
+
readonly kind: "manual";
|
|
143
|
+
readonly issuer: "apple";
|
|
144
|
+
readonly documentation: "https://developer.apple.com/account/resources/authkeys/list";
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
readonly "auth-facebook-credentials": {
|
|
148
|
+
readonly backend: "d1";
|
|
149
|
+
readonly scope: "environment";
|
|
150
|
+
readonly rotatable: false;
|
|
151
|
+
readonly valueType: "json";
|
|
152
|
+
readonly schema: z.ZodObject<{
|
|
153
|
+
clientId: z.ZodString;
|
|
154
|
+
clientSecret: z.ZodString;
|
|
155
|
+
}, z.core.$strip>;
|
|
156
|
+
readonly origin: {
|
|
157
|
+
readonly kind: "obtained";
|
|
158
|
+
readonly issuer: "facebook";
|
|
159
|
+
readonly documentation: "https://developers.facebook.com/apps/";
|
|
160
|
+
};
|
|
161
|
+
readonly rotation: {
|
|
162
|
+
readonly kind: "manual";
|
|
163
|
+
readonly issuer: "facebook";
|
|
164
|
+
readonly documentation: "https://developers.facebook.com/apps/";
|
|
165
|
+
};
|
|
72
166
|
};
|
|
167
|
+
readonly "auth-github-credentials": {
|
|
168
|
+
readonly backend: "d1";
|
|
169
|
+
readonly scope: "environment";
|
|
170
|
+
readonly rotatable: false;
|
|
171
|
+
readonly valueType: "json";
|
|
172
|
+
readonly schema: z.ZodObject<{
|
|
173
|
+
clientId: z.ZodString;
|
|
174
|
+
clientSecret: z.ZodString;
|
|
175
|
+
}, z.core.$strip>;
|
|
176
|
+
readonly origin: {
|
|
177
|
+
readonly kind: "obtained";
|
|
178
|
+
readonly issuer: "github";
|
|
179
|
+
readonly documentation: "https://github.com/settings/developers";
|
|
180
|
+
};
|
|
181
|
+
readonly rotation: {
|
|
182
|
+
readonly kind: "manual";
|
|
183
|
+
readonly issuer: "github";
|
|
184
|
+
readonly documentation: "https://github.com/settings/developers";
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* **The registry `auth()` contributes, from its own configuration (#602).**
|
|
190
|
+
*
|
|
191
|
+
* The session secret's overlap follows the configured session lifetime — {@link sessionSecretOverlapDays} —
|
|
192
|
+
* and it is both the overlap and its floor: an adopter who lengthens sessions lengthens the overlap with
|
|
193
|
+
* them, rather than holding a seven-day overlap against a thirty-day session. `rotateEveryDays` is
|
|
194
|
+
* `sessionSecretRotateEveryDays`, and only an adopter sets it: the kit turns no unattended rotation on.
|
|
195
|
+
*
|
|
196
|
+
* Checked by `defineSecretRegistry` like every registry, so a period no longer than the session lifetime is
|
|
197
|
+
* refused here, at `auth()`, naming the secret — rather than at a 03:00 cron that could only skip it.
|
|
198
|
+
*
|
|
199
|
+
* **A period is refused beside a plugin that seals rows under the session secret** —
|
|
200
|
+
* {@link SESSION_SECRET_SEALING_PLUGINS}. Only the JWKS keys are moved before a retirement; a plugin's own
|
|
201
|
+
* sealed rows would be left under the retired version, and nothing could open them again.
|
|
202
|
+
*/
|
|
203
|
+
export declare function authSecretsRegistryFor(config: {
|
|
204
|
+
sessionExpiresIn: number;
|
|
205
|
+
sessionSecretRotateEveryDays?: number;
|
|
206
|
+
plugins?: readonly {
|
|
207
|
+
id: string;
|
|
208
|
+
}[];
|
|
209
|
+
}): {
|
|
73
210
|
readonly "auth-google-credentials": {
|
|
74
211
|
readonly backend: "d1";
|
|
75
212
|
readonly scope: "environment";
|
|
@@ -151,6 +288,30 @@ export declare const authSecretsRegistry: {
|
|
|
151
288
|
readonly documentation: "https://github.com/settings/developers";
|
|
152
289
|
};
|
|
153
290
|
};
|
|
291
|
+
readonly "auth-session-secret": {
|
|
292
|
+
readonly backend: "d1";
|
|
293
|
+
readonly scope: "environment";
|
|
294
|
+
readonly rotatable: true;
|
|
295
|
+
readonly valueType: "text";
|
|
296
|
+
readonly devValue: "random";
|
|
297
|
+
readonly origin: {
|
|
298
|
+
readonly kind: "minted";
|
|
299
|
+
readonly recipe: {
|
|
300
|
+
readonly kind: "random";
|
|
301
|
+
readonly bytes: 32;
|
|
302
|
+
readonly encoding: "base64url";
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
readonly rotation: {
|
|
306
|
+
readonly kind: "local";
|
|
307
|
+
};
|
|
308
|
+
readonly overlap: {
|
|
309
|
+
readonly days: number;
|
|
310
|
+
readonly minimumDays: number;
|
|
311
|
+
readonly reencrypt: readonly ["auth-jwks"];
|
|
312
|
+
};
|
|
313
|
+
readonly rotateEveryDays?: number | undefined;
|
|
314
|
+
};
|
|
154
315
|
};
|
|
155
316
|
/**
|
|
156
317
|
* Which provider a credential belongs to — the join the CLI must never make by spelling (#541).
|
|
@@ -179,8 +340,14 @@ export type AuthProviderToggles = Record<(typeof PROVIDER_CREDENTIALS)[number][0
|
|
|
179
340
|
* do to turn this on* as well as *why am I being shown this*.
|
|
180
341
|
*/
|
|
181
342
|
export declare function inapplicableProviderSecrets(providers: AuthProviderToggles): Record<string, string>;
|
|
182
|
-
/** Resolve the Better Auth session secret for this invocation. */
|
|
343
|
+
/** Resolve the Better Auth session secret for this invocation — the current version alone. */
|
|
183
344
|
export declare function resolveSessionSecret(env: SecretsStoreEnv): Promise<string>;
|
|
345
|
+
/**
|
|
346
|
+
* Resolve every retained version of the session secret (#602) — what an instance needs to open values sealed
|
|
347
|
+
* under the previous version, and what a credential signed under it is verified against. One read through
|
|
348
|
+
* the same cached accessor as {@link resolveSessionSecret}.
|
|
349
|
+
*/
|
|
350
|
+
export declare function resolveSessionSecrets(env: SecretsStoreEnv): Promise<SessionSecretVersions>;
|
|
184
351
|
/** Resolve the Google OAuth credential pair for this invocation (only call when Google is enabled). */
|
|
185
352
|
export declare function resolveGoogleCredentials(env: SecretsStoreEnv): Promise<GoogleOAuthCredentials>;
|
|
186
353
|
/** Resolve the Apple Sign-In credentials for this invocation (only call when Apple is enabled). */
|