@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
package/src/http/middleware.ts
CHANGED
|
@@ -5,8 +5,10 @@ import type { PithyHonoEnv, PithyMiddleware } from "@pithy-sh/core/src/capabilit
|
|
|
5
5
|
import { UnauthorizedError } from "@pithy-sh/core/src/error/pithyError";
|
|
6
6
|
import { AuthContext } from "@pithy-sh/core/src/http/authContext";
|
|
7
7
|
import { isLocale } from "@pithy-sh/core/src/i18n/locale";
|
|
8
|
-
import type { MiddlewareHandler } from "hono";
|
|
9
|
-
import type { AuthWiring } from "../capability";
|
|
8
|
+
import type { Context, MiddlewareHandler } from "hono";
|
|
9
|
+
import type { AuthWiring, ScopeResolver, ScopeResolverSession } from "../capability";
|
|
10
|
+
import type { AuthInstance } from "../instance/auth";
|
|
11
|
+
import { withResignedCredentials } from "./credentialResign";
|
|
10
12
|
import { getAuthInstance } from "./resolve";
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -22,47 +24,110 @@ function authenticatedDate(session: unknown): Date | null {
|
|
|
22
24
|
return value instanceof Date ? value : null;
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The scopes this request's caller resolves to — what the adopter's resolver answered, or `[]`.
|
|
29
|
+
*
|
|
30
|
+
* **Closed on every failure, and never fatal** (#560). A resolver that throws or rejects, and one that answers
|
|
31
|
+
* something other than a list of strings, both leave the request with no scopes and a warning: a gate then
|
|
32
|
+
* refuses it as it would any untrusted caller, rather than the request becoming a 500 or — worse — a
|
|
33
|
+
* malformed answer reaching a guard that would read `includes` off a string. Validated through
|
|
34
|
+
* `AuthContext`'s own field, so this and the context the middleware publishes cannot disagree on the shape.
|
|
35
|
+
*
|
|
36
|
+
* The warning names the session and never the answer: whatever the resolver handed back is the adopter's,
|
|
37
|
+
* and a log is not where to learn what a caller was trusted with.
|
|
38
|
+
*/
|
|
39
|
+
async function resolvedScopes(
|
|
40
|
+
c: Context<PithyHonoEnv>,
|
|
41
|
+
resolve: ScopeResolver | undefined,
|
|
42
|
+
session: ScopeResolverSession,
|
|
43
|
+
): Promise<string[]> {
|
|
44
|
+
if (resolve === undefined) return [];
|
|
45
|
+
let answer: unknown;
|
|
46
|
+
try {
|
|
47
|
+
answer = await resolve(c, session);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
c.var.log.child("auth").warn("resolveScopes failed; this request carries no scopes", {
|
|
50
|
+
sessionId: session.sessionId,
|
|
51
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
52
|
+
});
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
const parsed = AuthContext.shape.scopes.safeParse(answer);
|
|
56
|
+
if (!parsed.success || answer === undefined) {
|
|
57
|
+
c.var.log
|
|
58
|
+
.child("auth")
|
|
59
|
+
.warn("resolveScopes answered something that is not a list of strings; this request carries no scopes", {
|
|
60
|
+
sessionId: session.sessionId,
|
|
61
|
+
});
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return parsed.data;
|
|
65
|
+
}
|
|
66
|
+
|
|
25
67
|
export function createSessionMiddleware(wiring: AuthWiring): PithyMiddleware {
|
|
26
68
|
return (app) => {
|
|
27
69
|
app.use("*", async (c, next) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// through `AuthContext.parse`, so a column holding something that is not a tag lands as
|
|
38
|
-
// `undefined` rather than reaching `Intl`.
|
|
39
|
-
const stored = (session.user as { locale?: unknown }).locale;
|
|
40
|
-
c.set(
|
|
41
|
-
"auth",
|
|
42
|
-
AuthContext.parse({
|
|
43
|
-
userId: session.user.id,
|
|
44
|
-
sessionId: session.session.id,
|
|
45
|
-
scopes: [],
|
|
46
|
-
locale: typeof stored === "string" && isLocale(stored) ? stored : null,
|
|
47
|
-
// Published for the same reason `locale` is: the session lookup has already loaded the
|
|
48
|
-
// row, so a gate that needs it should not pay for a second read. The adapter hands back
|
|
49
|
-
// a `Date`; a session predating the column hands back null, which reads as "cannot say".
|
|
50
|
-
// Guarded like `locale` beside it, and for a worse failure: `z.date()` throws on a
|
|
51
|
-
// string, the catch below swallows it, and every authenticated request in the Worker
|
|
52
|
-
// becomes anonymous — a total outage presenting as "everyone is logged out".
|
|
53
|
-
authenticatedAt: authenticatedDate(session.session),
|
|
54
|
-
}),
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
} catch {
|
|
58
|
-
// Leave `auth` null; the credential was missing/invalid.
|
|
59
|
-
}
|
|
70
|
+
if (!c.req.raw.headers.has("authorization") && !c.req.raw.headers.has("cookie")) return await next();
|
|
71
|
+
// A credential signed under a session secret this deployment has since rotated is re-signed under the
|
|
72
|
+
// current one before anything reads it (#602), and the re-signed one rides back on the response. A
|
|
73
|
+
// failure building the instance is not this middleware's to raise, so it is left to the routes.
|
|
74
|
+
let instance: AuthInstance | undefined;
|
|
75
|
+
try {
|
|
76
|
+
instance = await getAuthInstance(c, wiring);
|
|
77
|
+
} catch {
|
|
78
|
+
instance = undefined;
|
|
60
79
|
}
|
|
61
|
-
await next();
|
|
80
|
+
if (instance === undefined) return await next();
|
|
81
|
+
const built = instance;
|
|
82
|
+
await withResignedCredentials(c, built, async () => {
|
|
83
|
+
await resolveSession(c, wiring, built);
|
|
84
|
+
await next();
|
|
85
|
+
});
|
|
62
86
|
});
|
|
63
87
|
};
|
|
64
88
|
}
|
|
65
89
|
|
|
90
|
+
/** Fill `c.var.auth` from the request's credential, or leave it null. Never throws. */
|
|
91
|
+
async function resolveSession(c: Context<PithyHonoEnv>, wiring: AuthWiring, instance: AuthInstance): Promise<void> {
|
|
92
|
+
const headers = c.req.raw.headers;
|
|
93
|
+
try {
|
|
94
|
+
const session = await instance.api.getSession({ headers });
|
|
95
|
+
if (session) {
|
|
96
|
+
// Before the context is built, so a resolver sees the request exactly as it arrived and the
|
|
97
|
+
// context is published once, whole. Per request and never cached: the answer is about this
|
|
98
|
+
// request's caller, and a cached one is a revocation that has not taken effect (#560).
|
|
99
|
+
const scopes = await resolvedScopes(c, wiring.resolveScopes, {
|
|
100
|
+
userId: session.user.id,
|
|
101
|
+
sessionId: session.session.id,
|
|
102
|
+
});
|
|
103
|
+
// `locale` comes off the user row the session lookup already loaded, so publishing it
|
|
104
|
+
// costs nothing — and it is the `user` link of `@pithy-sh/i18n`'s server chain, the one
|
|
105
|
+
// that makes a reader's stored choice outrank their device's `Accept-Language`. Read
|
|
106
|
+
// through `AuthContext.parse`, so a column holding something that is not a tag lands as
|
|
107
|
+
// `undefined` rather than reaching `Intl`.
|
|
108
|
+
const stored = (session.user as { locale?: unknown }).locale;
|
|
109
|
+
c.set(
|
|
110
|
+
"auth",
|
|
111
|
+
AuthContext.parse({
|
|
112
|
+
userId: session.user.id,
|
|
113
|
+
sessionId: session.session.id,
|
|
114
|
+
scopes,
|
|
115
|
+
locale: typeof stored === "string" && isLocale(stored) ? stored : null,
|
|
116
|
+
// Published for the same reason `locale` is: the session lookup has already loaded the
|
|
117
|
+
// row, so a gate that needs it should not pay for a second read. The adapter hands back
|
|
118
|
+
// a `Date`; a session predating the column hands back null, which reads as "cannot say".
|
|
119
|
+
// Guarded like `locale` beside it, and for a worse failure: `z.date()` throws on a
|
|
120
|
+
// string, the catch below swallows it, and every authenticated request in the Worker
|
|
121
|
+
// becomes anonymous — a total outage presenting as "everyone is logged out".
|
|
122
|
+
authenticatedAt: authenticatedDate(session.session),
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
} catch {
|
|
127
|
+
// Leave `auth` null; the credential was missing/invalid.
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
66
131
|
/**
|
|
67
132
|
* The gate other capabilities stack on a protected route. Rejects a request whose `AuthContext` was
|
|
68
133
|
* not filled (no valid credential) with a `PithyError` `auth/invalid_token` (401).
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
*
|
|
41
41
|
* | Code | Emitted only when |
|
|
42
42
|
* | --- | --- |
|
|
43
|
-
* | `account_not_linked` | a user row **did** match (`better-auth/dist/oauth2/link-account.mjs:
|
|
44
|
-
* | `signup_disabled` | **no** row matched (`:
|
|
43
|
+
* | `account_not_linked` | a user row **did** match (`better-auth/dist/oauth2/link-account.mjs:142`) |
|
|
44
|
+
* | `signup_disabled` | **no** row matched (`:257`) |
|
|
45
45
|
*
|
|
46
46
|
* Both leave through one line — `redirectOnError(result.error.split(" ").join("_"))`,
|
|
47
|
-
* `dist/api/routes/callback.mjs:
|
|
47
|
+
* `dist/api/routes/callback.mjs:197` — so from outside the Worker they are one question with two
|
|
48
48
|
* answers. Press the provider button, read the `Location` header, repeat: an account-enumeration oracle
|
|
49
49
|
* needing one GitHub account, no account on the target, and no page render. It works against the
|
|
50
50
|
* configuration the kit's own security guidance recommends (`allowSignUp: false`, #554), so the
|
|
@@ -75,9 +75,10 @@
|
|
|
75
75
|
* ## This module is the second line of defense, not the only one
|
|
76
76
|
*
|
|
77
77
|
* It reads the `Location` a refused callback answered with — which is the output of
|
|
78
|
-
* `redirectOnError`
|
|
79
|
-
*
|
|
80
|
-
*
|
|
78
|
+
* `redirectOnError` (`callback.mjs:78`), built on a value the caller supplied. 1.7.1 concatenated it raw;
|
|
79
|
+
* 1.7.11 parses it with `new URL` in `@better-auth/core`'s `appendQueryParams`, which sets the query
|
|
80
|
+
* before any fragment and throws on a `//` or `/\` input. It was walked around twice on 1.7.1, and the second bypass
|
|
81
|
+
* was the diagnosis: **every input shape where that construction and this parsing disagree is another one**, so patching the parsing
|
|
81
82
|
* again only moves the report later. `./errorCallbackUrl` therefore guards the value on the way *in*,
|
|
82
83
|
* and by the time this module runs the string being parsed is one the kit produced.
|
|
83
84
|
*
|
|
@@ -123,7 +124,7 @@ interface RefusalVerdict {
|
|
|
123
124
|
* `providerRefusal.test.ts` reads Better Auth's own `OAUTH_CALLBACK_ERROR_CODES`, scans the
|
|
124
125
|
* `result.error` literals out of `link-account.mjs`, and scans the `new APIError(…, { code })` sites in
|
|
125
126
|
* both codebases — `better-auth`'s on the callback's path and the kit's across this whole package,
|
|
126
|
-
* because `callback.mjs:
|
|
127
|
+
* because `callback.mjs:192` re-emits *anything* thrown inside `handleOAuthUserInfo` as `?error=`. Every
|
|
127
128
|
* code any of them can produce must appear here. A dependency bump that adds one turns that red, and
|
|
128
129
|
* somebody writes a verdict for it. So the roster records a *review*, and the review cannot silently fall
|
|
129
130
|
* behind the thing it reviews.
|
|
@@ -140,11 +141,11 @@ const PROVIDER_REFUSAL_VERDICTS: Readonly<Record<string, RefusalVerdict>> = {
|
|
|
140
141
|
// ── Decided by the user table. These are the defect. ───────────────────────────────────────────
|
|
141
142
|
account_not_linked: {
|
|
142
143
|
collapse: true,
|
|
143
|
-
why: "link-account.mjs:
|
|
144
|
+
why: "link-account.mjs:142 — returned only inside `if (dbUser)`, so it is literally the statement that a row matched.",
|
|
144
145
|
},
|
|
145
146
|
signup_disabled: {
|
|
146
147
|
collapse: true,
|
|
147
|
-
why: "link-account.mjs:
|
|
148
|
+
why: "link-account.mjs:257 — the `else` of that same branch, so it is literally the statement that none did.",
|
|
148
149
|
},
|
|
149
150
|
EMAIL_NOT_VERIFIED: {
|
|
150
151
|
collapse: true,
|
|
@@ -152,15 +153,20 @@ const PROVIDER_REFUSAL_VERDICTS: Readonly<Record<string, RefusalVerdict>> = {
|
|
|
152
153
|
},
|
|
153
154
|
unable_to_create_user: {
|
|
154
155
|
collapse: true,
|
|
155
|
-
why: "link-account.mjs:
|
|
156
|
+
why: "link-account.mjs:301/308 — the create path only, so it sits on the no-row side exactly as `signup_disabled` does. A fault rather than a refusal, and still an answer to the question being asked.",
|
|
156
157
|
},
|
|
157
158
|
INVALID_PROFILE_FIELD: {
|
|
158
159
|
collapse: true,
|
|
159
|
-
why: "The kit's `user.update.before` hook, and **the branch it sits on was read wrong the first time.** `if (dbUser) {` opens at link-account.mjs:
|
|
160
|
+
why: "The kit's `user.update.before` hook, and **the branch it sits on was read wrong the first time.** `if (dbUser) {` opens at link-account.mjs:133 and the `if (!linkedAccount) {…} else {…}` pair sits *inside* it, so the ownership argument that carries `unable_to_update_account` does not reach here: the `updateUser` writes that can carry a provider's `name`/`image` are the `overrideUserInfo` write at :238, which runs after **either** sub-branch, and since 1.7.3 the `updateUserInfoOnLink` write at :189 on the branch that has just linked an account that did not exist a line earlier. What every path to it does share is `if (dbUser)`: a matched row. The other side of that branch calls `createUser`, where the kit's `user.create.before` **sanitizes** the same two fields instead of refusing them. So a hostile provider display name answers `?error=INVALID_PROFILE_FIELD` against an address that has a row and a completed sign-in against one that does not, which is the oracle with a different name on it.",
|
|
160
161
|
},
|
|
161
162
|
validation_context_missing: {
|
|
162
163
|
collapse: true,
|
|
163
|
-
why: "internal-adapter.mjs:160 — raised when `getCurrentAuthContext()` fails inside `createUser`, and `createUser` is the no-row side. `updateUser` runs no such check (internal-adapter.mjs:
|
|
164
|
+
why: "internal-adapter.mjs:160 — raised when `getCurrentAuthContext()` fails inside `createUser`, and `createUser` is the no-row side. `updateUser` runs no such check (internal-adapter.mjs:616), so this code cannot be observed against an address that has a row: it is `signup_disabled`'s shape reached through the adopter's `validateUserInfo` option rather than through the sign-up policy.",
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
unable_to_link_account: {
|
|
168
|
+
collapse: true,
|
|
169
|
+
why: "Two producers, and the verdict follows the one that reads our rows. `linkOAuthAccount` (link-account.mjs:45/68) answers it on `/link-social`, where the caller is signed in as the user being changed. But `handleOAuthUserInfo` answers it too, inside `if (dbUser)` when the account write fails (:171/:184), so on the social callback it says a row matched, and `unable_to_create_user` is its other half. Collapsing costs the signed-in linker a specific code for a fault. Letting it travel would cost the oracle. Corrected in #787; the earlier verdict read only the link flow.",
|
|
164
170
|
},
|
|
165
171
|
|
|
166
172
|
// ── The caller's own request, or the provider's. Nothing to do with our rows. ──────────────────
|
|
@@ -174,7 +180,7 @@ const PROVIDER_REFUSAL_VERDICTS: Readonly<Record<string, RefusalVerdict>> = {
|
|
|
174
180
|
},
|
|
175
181
|
invalid_callback_request: {
|
|
176
182
|
collapse: false,
|
|
177
|
-
why: "callback.mjs:
|
|
183
|
+
why: "callback.mjs:54 — the callback's own query or body would not parse. Raised before `parseState`, so nothing had been read from anywhere yet.",
|
|
178
184
|
},
|
|
179
185
|
oauth_provider_not_found: {
|
|
180
186
|
collapse: false,
|
|
@@ -206,15 +212,15 @@ const PROVIDER_REFUSAL_VERDICTS: Readonly<Record<string, RefusalVerdict>> = {
|
|
|
206
212
|
},
|
|
207
213
|
email_not_verified: {
|
|
208
214
|
collapse: false,
|
|
209
|
-
why: "Better Auth's lower-case code, from `requireEmailVerification` (link-account.mjs:
|
|
215
|
+
why: "Better Auth's lower-case code, from `requireEmailVerification` (link-account.mjs:317) — which the kit does not set. Reachable for a registering and a returning user alike, so it names no row either way. Not to be confused with the kit's upper-case `EMAIL_NOT_VERIFIED` above; the two are different strings from different places and only one of them is the oracle.",
|
|
210
216
|
},
|
|
211
217
|
unable_to_create_session: {
|
|
212
218
|
collapse: false,
|
|
213
|
-
why: "link-account.mjs:
|
|
219
|
+
why: "link-account.mjs:324 — after the user is resolved, so it is reached from both sides of the branch equally.",
|
|
214
220
|
},
|
|
215
221
|
state_not_found: {
|
|
216
222
|
collapse: false,
|
|
217
|
-
why: "The request carried no state to parse. Raised at state.mjs:
|
|
223
|
+
why: "The request carried no state to parse. Raised at state.mjs:93, before any lookup.",
|
|
218
224
|
},
|
|
219
225
|
state_mismatch: {
|
|
220
226
|
collapse: false,
|
|
@@ -238,7 +244,7 @@ const PROVIDER_REFUSAL_VERDICTS: Readonly<Record<string, RefusalVerdict>> = {
|
|
|
238
244
|
},
|
|
239
245
|
account_hook_binding_conflict: {
|
|
240
246
|
collapse: false,
|
|
241
|
-
why: "link-account.mjs:
|
|
247
|
+
why: "link-account.mjs:175/231/291 — a hook moved the account binding out from under the write that had just been made. Raised on the link path, the sign-in path *and* the create path, so it is reached from both sides of `if (dbUser)` equally and names neither.",
|
|
242
248
|
},
|
|
243
249
|
validation_source_missing: {
|
|
244
250
|
collapse: false,
|
|
@@ -246,14 +252,10 @@ const PROVIDER_REFUSAL_VERDICTS: Readonly<Record<string, RefusalVerdict>> = {
|
|
|
246
252
|
},
|
|
247
253
|
validation_failed: {
|
|
248
254
|
collapse: false,
|
|
249
|
-
why: "validate-user-info.mjs:34 — the adopter's own `validateUserInfo` callback threw, and Better Auth fails closed. Called on the link path (link-account.mjs:
|
|
255
|
+
why: "validate-user-info.mjs:34 — the adopter's own `validateUserInfo` callback threw, and Better Auth fails closed. Called on the link path (link-account.mjs:24 and :148), the sign-in path (:192) and the create path (internal-adapter.mjs:164), so it is reachable whether or not a row matched. What that callback *returns* is the adopter's own code and travels off-roster, which is the same decision as for the provider's own `error` values.",
|
|
250
256
|
},
|
|
251
257
|
|
|
252
258
|
// ── The link flow. The caller already holds a session for the account in question. ─────────────
|
|
253
|
-
unable_to_link_account: {
|
|
254
|
-
collapse: false,
|
|
255
|
-
why: "callback.mjs:173/198, inside `if (link)` — reachable only on `/link-social`, where the caller is signed in as the user being changed. Telling somebody about their own account is not enumeration.",
|
|
256
|
-
},
|
|
257
259
|
email_does_not_match: {
|
|
258
260
|
collapse: false,
|
|
259
261
|
why: "The link flow, and the address compared against is the signed-in caller's own. The caller's account, as above.",
|
|
@@ -264,7 +266,7 @@ const PROVIDER_REFUSAL_VERDICTS: Readonly<Record<string, RefusalVerdict>> = {
|
|
|
264
266
|
},
|
|
265
267
|
unable_to_update_account: {
|
|
266
268
|
collapse: false,
|
|
267
|
-
why: "link-account.mjs:
|
|
269
|
+
why: "link-account.mjs:227, inside `if (linkedAccount)` — reaching it requires an account row already binding this provider identity to this user, and the caller proved control of that identity at the provider to get here. Ownership, not a matched row. (This is the argument `INVALID_PROFILE_FIELD` was wrongly given: that code's write sits outside this branch.)",
|
|
268
270
|
},
|
|
269
271
|
|
|
270
272
|
// ── The account-selection flow, which the social callback never enters. ────────────────────────
|
|
@@ -274,23 +276,19 @@ const PROVIDER_REFUSAL_VERDICTS: Readonly<Record<string, RefusalVerdict>> = {
|
|
|
274
276
|
// verdict a reader can check, where silence is not.
|
|
275
277
|
account_ownership_conflict: {
|
|
276
278
|
collapse: false,
|
|
277
|
-
why: "link-account.mjs:
|
|
278
|
-
},
|
|
279
|
-
account_provider_conflict: {
|
|
280
|
-
collapse: false,
|
|
281
|
-
why: "link-account.mjs:42, guarded by `requireExactAccountBinding`, which is `opts.selectedUser || opts.requireExactAccountBinding` — neither of which `callback.mjs` passes. Keyed by the caller's own provider identity, as above.",
|
|
279
|
+
why: "link-account.mjs:97, inside `if (opts.selectedUser && …)`. The lookup it reports on is keyed by the *provider* identity the caller has just proved control of, not by an address handed over — and the social callback passes no `selectedUser`, so this never reaches that redirect at all.",
|
|
282
280
|
},
|
|
283
281
|
user_not_found: {
|
|
284
282
|
collapse: false,
|
|
285
|
-
why: "link-account.mjs:
|
|
283
|
+
why: "link-account.mjs:109 — `findUserById(opts.selectedUser.userId)`, so it answers about a user id the caller was already handed, on a flow the social callback does not enter. It reads a row by id, never by a provider-resolved address.",
|
|
286
284
|
},
|
|
287
285
|
user_hook_selection_conflict: {
|
|
288
286
|
collapse: false,
|
|
289
|
-
why: "link-account.mjs:
|
|
287
|
+
why: "link-account.mjs:249, inside `if (opts.selectedUser …)`. A hook returned a different user than the one the caller picked from a list they had already been shown, and the social callback never picks one.",
|
|
290
288
|
},
|
|
291
289
|
session_hook_user_conflict: {
|
|
292
290
|
collapse: false,
|
|
293
|
-
why: "link-account.mjs:
|
|
291
|
+
why: "link-account.mjs:328 — after the user is resolved and the session minted, under the same `requireExactAccountBinding` gate. Reached from both sides of `if (dbUser)` when it is reached at all, which on the social callback is never.",
|
|
294
292
|
},
|
|
295
293
|
};
|
|
296
294
|
|
|
@@ -344,7 +342,7 @@ export interface CollapsedRefusal {
|
|
|
344
342
|
*
|
|
345
343
|
* - **It need not be absolute.** `api/middlewares/origin-check.mjs` passes `allowRelativePaths: true`,
|
|
346
344
|
* `matchesOriginPattern` admits `/path?query`, `oauth2/state.mjs` stores the value as a bare
|
|
347
|
-
* `z.string().optional()`, and `redirectOnError`
|
|
345
|
+
* `z.string().optional()`, and `redirectOnError` keeps it root-relative. So a relative `Location` is a
|
|
348
346
|
* supported answer, and returning `undefined` to one sent the true code to the browser and wrote no
|
|
349
347
|
* audit row.
|
|
350
348
|
* - **`error` need not be the only one.** `redirectOnError` *appends* `&error=<code>`. An
|
package/src/http/resolve.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import type { D1Database } from "@cloudflare/workers-types";
|
|
5
5
|
import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
|
|
6
6
|
import { InternalError } from "@pithy-sh/core/src/error/pithyError";
|
|
7
|
+
import { createWorkerLogger } from "@pithy-sh/core/src/logger/worker";
|
|
7
8
|
import type { EmailEnqueueEnv } from "@pithy-sh/email/src/capability";
|
|
8
9
|
import type { SecretsStoreEnv } from "@pithy-sh/secrets/src/env/bindings";
|
|
9
10
|
import type { Context } from "hono";
|
|
@@ -11,13 +12,14 @@ import type { AuthWiring } from "../capability";
|
|
|
11
12
|
import { authDatabase } from "../data/tables";
|
|
12
13
|
import { makeSendAuthEmail, type ResolveRecipientLocale } from "../email/send";
|
|
13
14
|
import { type AuthInstance, makeAuth } from "../instance/auth";
|
|
15
|
+
import { ensureJwksSealedUnderCurrent } from "../instance/jwksReencryption";
|
|
14
16
|
import { resolveProvider } from "../instance/providers";
|
|
15
17
|
import {
|
|
16
18
|
resolveAppleCredentials,
|
|
17
19
|
resolveFacebookCredentials,
|
|
18
20
|
resolveGithubCredentials,
|
|
19
21
|
resolveGoogleCredentials,
|
|
20
|
-
|
|
22
|
+
resolveSessionSecrets,
|
|
21
23
|
} from "../instance/secrets";
|
|
22
24
|
import { baseURLResolver } from "./baseUrl";
|
|
23
25
|
|
|
@@ -103,8 +105,8 @@ async function buildAuthInstance(c: Context<PithyHonoEnv>, wiring: AuthWiring):
|
|
|
103
105
|
//
|
|
104
106
|
// A held failure belongs to its own secret (#170), so an unreadable provider credential does not
|
|
105
107
|
// disturb the session secret's own read, and a *disabled* provider never calls `.get()` at all.
|
|
106
|
-
const [
|
|
107
|
-
|
|
108
|
+
const [sessionSecrets, google, apple, facebook, github] = await Promise.all([
|
|
109
|
+
resolveSessionSecrets(env),
|
|
108
110
|
resolveProvider(cfg.google.enabled, () => resolveGoogleCredentials(env)),
|
|
109
111
|
resolveProvider(cfg.apple.enabled, () => resolveAppleCredentials(env)),
|
|
110
112
|
resolveProvider(cfg.facebook.enabled, () => resolveFacebookCredentials(env)),
|
|
@@ -112,6 +114,27 @@ async function buildAuthInstance(c: Context<PithyHonoEnv>, wiring: AuthWiring):
|
|
|
112
114
|
]);
|
|
113
115
|
const expiresMinutes = Math.max(1, Math.round(cfg.verificationExpiresIn / 60));
|
|
114
116
|
const d1 = resolveDb(c.env, cfg.database);
|
|
117
|
+
// The current version signs; every retained one opens (#602). A version set with no current entry is a
|
|
118
|
+
// corrupt envelope, and the store's own reader has already refused that — this narrows it for the type.
|
|
119
|
+
const secret = sessionSecrets.versions[sessionSecrets.currentVersion];
|
|
120
|
+
if (secret === undefined) {
|
|
121
|
+
throw new InternalError({
|
|
122
|
+
message: "Authentication is misconfigured.",
|
|
123
|
+
detail: "auth-session-secret resolved with no value at its current version",
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// Mid-rotation, move the JWKS keys under the current version before the old one is retired, and record this
|
|
127
|
+
// database as a holder either way. Once per version per isolate, never fatal — see
|
|
128
|
+
// `../instance/jwksReencryption.ts`.
|
|
129
|
+
await ensureJwksSealedUnderCurrent({
|
|
130
|
+
db: authDatabase(d1),
|
|
131
|
+
holder: cfg.database,
|
|
132
|
+
secrets: env.SECRETS,
|
|
133
|
+
versions: sessionSecrets,
|
|
134
|
+
// Read off the context when a backend seeded one, as `createBackend` always does; a hand-built app in a
|
|
135
|
+
// test may not have, and a re-encryption that cannot say what it did must not break the request.
|
|
136
|
+
log: (c.get("log") ?? createWorkerLogger({ name: "auth" })).child("auth"),
|
|
137
|
+
});
|
|
115
138
|
const listener = wiring.onSessionRevoked;
|
|
116
139
|
return makeAuth({
|
|
117
140
|
db: authDatabase(d1),
|
|
@@ -120,6 +143,7 @@ async function buildAuthInstance(c: Context<PithyHonoEnv>, wiring: AuthWiring):
|
|
|
120
143
|
// has none.
|
|
121
144
|
...(listener ? { onSessionRevoked: (session: { id: string; userId: string }) => listener(session, d1) } : {}),
|
|
122
145
|
secret,
|
|
146
|
+
sessionSecrets,
|
|
123
147
|
// Never `cfg.baseURL` directly. The instance derives the session cookie's name, the OAuth callback
|
|
124
148
|
// URLs, and the magic-link URL from whatever base URL it is handed, so in a `dev` composition every
|
|
125
149
|
// one of those has to name the address this run is actually serving on — not the production origin
|
package/src/http/responses.ts
CHANGED
|
@@ -197,3 +197,57 @@ export const AdminDeviceRevokeResponse = z
|
|
|
197
197
|
})
|
|
198
198
|
.describe("How many sessions the device revocation ended, and whether the registry row went with them.");
|
|
199
199
|
export type AdminDeviceRevokeResponse = z.output<typeof AdminDeviceRevokeResponse>;
|
|
200
|
+
|
|
201
|
+
/*
|
|
202
|
+
* The routes a signed-in person calls on their own account. These are not read across the management
|
|
203
|
+
* version boundary the admin schemas above are, but a client generated from the contract reads Workers on
|
|
204
|
+
* older releases too, so the same rule holds: a field added here later is `.optional()`.
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
/** `POST {base}/token/rotate`. */
|
|
208
|
+
export const TokenRotateResponse = z
|
|
209
|
+
.object({
|
|
210
|
+
accessToken: z
|
|
211
|
+
.string()
|
|
212
|
+
.describe("A fresh short-lived access token (a JWT) for the `Authorization: Bearer` header."),
|
|
213
|
+
refreshToken: z
|
|
214
|
+
.string()
|
|
215
|
+
.describe(
|
|
216
|
+
"The successor refresh credential: a new session token. The one presented is spent, and presenting it again past a short grace window revokes the whole family.",
|
|
217
|
+
),
|
|
218
|
+
expiresAt: z.iso.datetime().describe("When the successor session lapses, ISO-8601."),
|
|
219
|
+
})
|
|
220
|
+
.describe("The rotated credential pair: a new access token and the session token that replaces the one presented.");
|
|
221
|
+
export type TokenRotateResponse = z.output<typeof TokenRotateResponse>;
|
|
222
|
+
|
|
223
|
+
/** One of the caller's own registered devices. */
|
|
224
|
+
export const MyDeviceView = z
|
|
225
|
+
.object({
|
|
226
|
+
id: z.string().describe("The client-generated device id it registered at sign-in."),
|
|
227
|
+
userId: z.string().describe("The owning user's id: always the caller's own."),
|
|
228
|
+
platform: DevicePlatform.describe("The platform the device registered as."),
|
|
229
|
+
name: z.string().nullable().describe("The device's human label, or null."),
|
|
230
|
+
model: z.string().nullable().describe("The hardware model, or null."),
|
|
231
|
+
osVersion: z.string().nullable().describe("The device OS version at last sign-in, or null."),
|
|
232
|
+
appVersion: z.string().nullable().describe("The client app version at last sign-in, or null."),
|
|
233
|
+
pushToken: z.string().nullable().describe("The APNs or FCM push token the device registered, or null."),
|
|
234
|
+
lastIp: z.string().nullable().describe("The client IP at the device's most recent sign-in, or null."),
|
|
235
|
+
lastSeenAt: z.iso.datetime().describe("When the device was last seen, ISO-8601."),
|
|
236
|
+
createdAt: z.iso.datetime().describe("When the device first registered, ISO-8601."),
|
|
237
|
+
})
|
|
238
|
+
.describe("One device registered to the caller's own account.");
|
|
239
|
+
export type MyDeviceView = z.output<typeof MyDeviceView>;
|
|
240
|
+
|
|
241
|
+
/** `GET {base}/devices`. */
|
|
242
|
+
export const MyDevicesResponse = z
|
|
243
|
+
.object({
|
|
244
|
+
devices: z.array(MyDeviceView).describe("Every device registered to the caller, most recently seen first."),
|
|
245
|
+
})
|
|
246
|
+
.describe("The caller's own registered devices.");
|
|
247
|
+
export type MyDevicesResponse = z.output<typeof MyDevicesResponse>;
|
|
248
|
+
|
|
249
|
+
/** `POST {base}/devices/revoke`. */
|
|
250
|
+
export const MyDeviceRevokeResponse = z
|
|
251
|
+
.object({ revoked: RevokedCount })
|
|
252
|
+
.describe("How many of the device's sessions the revocation signed out. The device's row goes with them.");
|
|
253
|
+
export type MyDeviceRevokeResponse = z.output<typeof MyDeviceRevokeResponse>;
|
package/src/http/routes.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import { zValidator } from "@hono/zod-validator";
|
|
5
4
|
import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
|
|
6
5
|
import { NotFoundError, UnauthorizedError } from "@pithy-sh/core/src/error/pithyError";
|
|
6
|
+
import { describeRoute, type RouteResponse } from "@pithy-sh/core/src/http/routeSpec";
|
|
7
7
|
import { requireSameOrigin } from "@pithy-sh/core/src/http/sameOrigin";
|
|
8
|
-
import {
|
|
8
|
+
import { validate } from "@pithy-sh/core/src/http/validation";
|
|
9
9
|
import { STORED_IMAGE_HEADERS, storedImageBytes } from "@pithy-sh/core/src/image/storedImage";
|
|
10
10
|
import { TURNSTILE_LOGIN_ACTION } from "@pithy-sh/turnstile/src/config/config";
|
|
11
11
|
import { turnstile } from "@pithy-sh/turnstile/src/http/middleware";
|
|
@@ -29,10 +29,21 @@ import { requireAuth } from "./middleware";
|
|
|
29
29
|
import { requireFreshAuthentication } from "./providerFreshness";
|
|
30
30
|
import { collapseProviderRefusal } from "./providerRefusal";
|
|
31
31
|
import { getAuthInstance, resolveDb } from "./resolve";
|
|
32
|
+
import { MyDeviceRevokeResponse, MyDevicesResponse, TokenRotateResponse } from "./responses";
|
|
32
33
|
import { RevokeDeviceBody } from "./schemas";
|
|
33
34
|
|
|
34
35
|
type Ctx = Context<PithyHonoEnv>;
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
* What a route answers when the answer is Better Auth's: the catch-all, and the two endpoints of its that
|
|
39
|
+
* are mounted ahead of it for a gate. Its wire is its own contract (`handleBetterAuth` says why), so the
|
|
40
|
+
* kit's contract points at it rather than restating it.
|
|
41
|
+
*/
|
|
42
|
+
const BETTER_AUTH_ANSWER: RouteResponse = {
|
|
43
|
+
description: "Better Auth's own answer. See its endpoint reference.",
|
|
44
|
+
contentType: "application/json",
|
|
45
|
+
};
|
|
46
|
+
|
|
36
47
|
function db(c: Ctx, wiring: AuthWiring) {
|
|
37
48
|
return authDatabase(resolveDb(c.env, wiring.config.database));
|
|
38
49
|
}
|
|
@@ -85,11 +96,40 @@ export function createAuthRoutes(wiring: AuthWiring): (app: Hono<PithyHonoEnv>)
|
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
// Rotate the refresh credential: mint a new session, revoke the presented one, return a fresh JWT.
|
|
88
|
-
app.post(
|
|
99
|
+
app.post(
|
|
100
|
+
`${base}/token/rotate`,
|
|
101
|
+
describeRoute({
|
|
102
|
+
summary: "Trade the current refresh credential for a new access token and its successor.",
|
|
103
|
+
description:
|
|
104
|
+
"The presented session is spent. Presenting it again after a short grace window is read as theft, and revokes every session descended from the same sign-in.",
|
|
105
|
+
verification: ["bearer", "session"],
|
|
106
|
+
responses: { 200: TokenRotateResponse },
|
|
107
|
+
}),
|
|
108
|
+
csrf,
|
|
109
|
+
(c) => rotateToken(c, wiring),
|
|
110
|
+
);
|
|
89
111
|
// Device management (bearer/session gated; the revoke is CSRF-guarded as a mutating route).
|
|
90
|
-
app.get(
|
|
91
|
-
|
|
92
|
-
|
|
112
|
+
app.get(
|
|
113
|
+
`${base}/devices`,
|
|
114
|
+
describeRoute({
|
|
115
|
+
summary: "List the caller's own registered devices.",
|
|
116
|
+
verification: ["bearer", "session"],
|
|
117
|
+
responses: { 200: MyDevicesResponse },
|
|
118
|
+
}),
|
|
119
|
+
requireAuth(),
|
|
120
|
+
(c) => listMyDevices(c, wiring),
|
|
121
|
+
);
|
|
122
|
+
app.post(
|
|
123
|
+
`${base}/devices/revoke`,
|
|
124
|
+
describeRoute({
|
|
125
|
+
summary: "Sign out one of the caller's own devices and forget it.",
|
|
126
|
+
verification: ["bearer", "session"],
|
|
127
|
+
responses: { 200: MyDeviceRevokeResponse },
|
|
128
|
+
}),
|
|
129
|
+
requireAuth(),
|
|
130
|
+
csrf,
|
|
131
|
+
validate("json", RevokeDeviceBody),
|
|
132
|
+
(c) => revokeMyDevice(c, wiring, c.req.valid("json")),
|
|
93
133
|
);
|
|
94
134
|
|
|
95
135
|
// **Changing which providers can sign you in requires a recent authentication — both directions.**
|
|
@@ -97,18 +137,64 @@ export function createAuthRoutes(wiring: AuthWiring): (app: Hono<PithyHonoEnv>)
|
|
|
97
137
|
// carries the argument: Better Auth guards the two unevenly, and its guard on the unlink side reads
|
|
98
138
|
// `session.createdAt`, which `/token/rotate` resets. Neither takes a kit validator — the body is
|
|
99
139
|
// Better Auth's, and `handleBetterAuth` hands it `c.req.raw`, which is the catch-all's own reason.
|
|
100
|
-
app.post(
|
|
101
|
-
|
|
140
|
+
app.post(
|
|
141
|
+
`${base}/link-social`,
|
|
142
|
+
describeRoute({
|
|
143
|
+
summary: "Connect another sign-in provider to the caller's account.",
|
|
144
|
+
description:
|
|
145
|
+
"Better Auth's endpoint, behind a kit gate: the caller must have signed in within the last fifteen minutes, or it is refused with `auth/session_not_fresh`.",
|
|
146
|
+
verification: ["bearer", "session"],
|
|
147
|
+
responses: { 200: BETTER_AUTH_ANSWER },
|
|
148
|
+
}),
|
|
149
|
+
requireFreshAuthentication("link"),
|
|
150
|
+
(c) => handleBetterAuth(c, wiring),
|
|
151
|
+
);
|
|
152
|
+
app.post(
|
|
153
|
+
`${base}/unlink-account`,
|
|
154
|
+
describeRoute({
|
|
155
|
+
summary: "Disconnect a sign-in provider from the caller's account.",
|
|
156
|
+
description:
|
|
157
|
+
"Better Auth's endpoint, behind a kit gate: the caller must have signed in within the last fifteen minutes, or it is refused with `auth/session_not_fresh`.",
|
|
158
|
+
verification: ["bearer", "session"],
|
|
159
|
+
responses: { 200: BETTER_AUTH_ANSWER },
|
|
160
|
+
}),
|
|
161
|
+
requireFreshAuthentication("unlink"),
|
|
162
|
+
(c) => handleBetterAuth(c, wiring),
|
|
163
|
+
);
|
|
102
164
|
|
|
103
165
|
// The caller's own stored picture, as bytes a browser can cache. No id in the path — see
|
|
104
166
|
// `serveMyImage`, which is where the reason lives.
|
|
105
|
-
app.get(
|
|
167
|
+
app.get(
|
|
168
|
+
`${base}${PROFILE_IMAGE_PATH}`,
|
|
169
|
+
describeRoute({
|
|
170
|
+
summary: "Read the caller's own stored picture.",
|
|
171
|
+
description:
|
|
172
|
+
"A picture linked from a provider, or stored as a vector, is not served here and answers 404. The response is private and immutable: the URL a client is handed carries the picture's version.",
|
|
173
|
+
verification: ["bearer", "session"],
|
|
174
|
+
responses: {
|
|
175
|
+
200: { description: "The caller's stored picture, as PNG, JPEG or WebP bytes.", contentType: "image/*" },
|
|
176
|
+
},
|
|
177
|
+
}),
|
|
178
|
+
requireAuth(),
|
|
179
|
+
(c) => serveMyImage(c, wiring),
|
|
180
|
+
);
|
|
106
181
|
|
|
107
182
|
// The control-plane management surface. Registered here, before the catch-all below, or it is dead.
|
|
108
183
|
registerAuthAdminRoutes(wiring)(app);
|
|
109
184
|
|
|
110
185
|
// Better Auth owns the rest (sign-in, verify, callback, sign-out, /token, /jwks, revoke-sessions…).
|
|
111
|
-
app.all(
|
|
186
|
+
app.all(
|
|
187
|
+
`${base}/*`,
|
|
188
|
+
describeRoute({
|
|
189
|
+
summary: "Everything else under the auth path, answered by Better Auth.",
|
|
190
|
+
description:
|
|
191
|
+
"Sign-in, sign-up, verification, OAuth callbacks, sign-out, `/token`, `/jwks` and the rest of Better Auth's endpoints. Which credential an endpoint takes, if any, is its own decision.",
|
|
192
|
+
verification: ["public", "session", "bearer"],
|
|
193
|
+
methods: ["get", "post"],
|
|
194
|
+
responses: { 200: BETTER_AUTH_ANSWER },
|
|
195
|
+
}),
|
|
196
|
+
(c) => handleBetterAuth(c, wiring),
|
|
197
|
+
);
|
|
112
198
|
};
|
|
113
199
|
}
|
|
114
200
|
|
|
@@ -194,7 +280,7 @@ async function handleBetterAuth(c: Ctx, wiring: AuthWiring): Promise<Response> {
|
|
|
194
280
|
const instance = await getAuthInstance(c, wiring);
|
|
195
281
|
|
|
196
282
|
// **The first of the two guards on the refusal redirect (#625).** `errorCallbackURL` is the caller's
|
|
197
|
-
// string and `redirectOnError`
|
|
283
|
+
// string and `redirectOnError` builds the redirect on it, so the shape handed *in* decides
|
|
198
284
|
// whether the collapse below is reading a query at all. `./errorCallbackUrl` normalizes it to something
|
|
199
285
|
// the kit produced, or refuses it — and carries the argument for why guarding the input is not the same
|
|
200
286
|
// job as reading the output, and why both stay.
|
package/src/http/schemas.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { DevicePlatform } from "../data/device";
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The request schemas for the auth routes Pithy owns. Validation happens at the HTTP boundary
|
|
10
|
-
* (CLAUDE.md §Zod), declared on the route line with `
|
|
10
|
+
* (CLAUDE.md §Zod), declared on the route line with `validate(target, Schema)` — so
|
|
11
11
|
* reading `routes.ts` and `adminRoutes.ts` tells you what each route accepts without opening a handler.
|
|
12
12
|
*
|
|
13
13
|
* Only Pithy's own routes appear here. Everything under `basePath` that Better Auth owns validates
|