@pithy-sh/auth 0.2.1 → 0.4.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/dist/audit/actions.d.ts +12 -0
- package/dist/audit/actions.d.ts.map +1 -1
- package/dist/audit/actions.js +12 -0
- package/dist/audit/emit.d.ts +12 -0
- package/dist/audit/emit.d.ts.map +1 -1
- package/dist/audit/emit.js +19 -1
- package/dist/capability.d.ts +37 -5
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +30 -9
- package/dist/client/api.d.ts +8 -0
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +7 -0
- package/dist/client/projection.d.ts +22 -0
- package/dist/client/projection.d.ts.map +1 -1
- package/dist/data/betterAuth.d.ts +1 -0
- package/dist/data/betterAuth.d.ts.map +1 -1
- package/dist/data/betterAuth.js +2 -1
- package/dist/data/kitFields.d.ts +23 -1
- package/dist/data/kitFields.d.ts.map +1 -1
- package/dist/data/kitFields.js +23 -1
- package/dist/data/tables.d.ts +1 -0
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/http/linkFreshness.d.ts +88 -0
- package/dist/http/linkFreshness.d.ts.map +1 -0
- package/dist/http/linkFreshness.js +91 -0
- package/dist/http/middleware.d.ts +0 -7
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +7 -1
- package/dist/http/resolve.js +7 -0
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +4 -0
- package/dist/instance/auth.d.ts +93 -13
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +90 -8
- package/dist/instance/githubUserInfo.d.ts +129 -0
- package/dist/instance/githubUserInfo.d.ts.map +1 -0
- package/dist/instance/githubUserInfo.js +153 -0
- package/dist/migrations/0002_session_authenticated_at.d.ts +39 -0
- package/dist/migrations/0002_session_authenticated_at.d.ts.map +1 -0
- package/dist/migrations/0002_session_authenticated_at.js +47 -0
- package/dist/migrations/set.d.ts +20 -0
- package/dist/migrations/set.d.ts.map +1 -0
- package/dist/migrations/set.js +24 -0
- package/dist/seeds/devSession.d.ts.map +1 -1
- package/dist/seeds/devSession.js +2 -1
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +4 -2
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/github-oauth.md +55 -0
- package/package.json +5 -5
- package/src/audit/actions.ts +12 -0
- package/src/audit/emit.ts +24 -0
- package/src/capability.ts +76 -10
- package/src/client/api.ts +8 -1
- package/src/client/projection.ts +22 -0
- package/src/data/betterAuth.ts +3 -0
- package/src/data/kitFields.ts +19 -1
- package/src/http/linkFreshness.ts +130 -0
- package/src/http/middleware.ts +13 -0
- package/src/http/resolve.ts +10 -0
- package/src/http/routes.ts +28 -1
- package/src/instance/auth.ts +113 -7
- package/src/instance/githubUserInfo.ts +212 -0
- package/src/migrations/0002_session_authenticated_at.ts +50 -0
- package/src/migrations/set.ts +23 -0
- package/src/seeds/devSession.ts +2 -0
- package/src/test-utils/liveApp.ts +4 -2
- package/src/version.generated.ts +1 -1
package/dist/audit/actions.d.ts
CHANGED
|
@@ -39,6 +39,18 @@ export declare const AuthAuditActions: {
|
|
|
39
39
|
* cost" is answerable from the same place every other auth question is.
|
|
40
40
|
*/
|
|
41
41
|
readonly providerUnavailable: "auth/provider_unavailable";
|
|
42
|
+
/**
|
|
43
|
+
* Somebody signed in tried to attach a social provider without having authenticated recently enough.
|
|
44
|
+
* Outcome `denied`, severity `warning`.
|
|
45
|
+
*
|
|
46
|
+
* Attaching an identity grants permanent access — after it, sign-in resolves by account id and the email
|
|
47
|
+
* stops mattering — so this is the row that answers "was somebody walking a stolen credential at the
|
|
48
|
+
* account-takeover step". One is a person who left a tab open; a run of them against one user id is the
|
|
49
|
+
* incident, and without the row there is nothing to count.
|
|
50
|
+
*
|
|
51
|
+
* Mirrors the error code, which is this file's one precedent for doing so.
|
|
52
|
+
*/
|
|
53
|
+
readonly sessionNotFresh: "auth/session_not_fresh";
|
|
42
54
|
/**
|
|
43
55
|
* The admin actions, emitted only from the control-plane surface (`http/adminRoutes.ts`) and always
|
|
44
56
|
* with `actorType: "control-plane"` — a management client is not a user of the adopter's app, so its
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/audit/actions.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;IAC3B,+FAA+F;aAC/F,MAAM,EAAE,aAAa;IACrB,iDAAiD;aACjD,OAAO,EAAE,cAAc;IACvB,yFAAyF;aACzF,YAAY,EAAE,oBAAoB;IAClC,sHAAsH;aACtH,kBAAkB,EAAE,2BAA2B;IAC/C,4DAA4D;aAC5D,aAAa,EAAE,sBAAsB;IACrC,4DAA4D;aAC5D,OAAO,EAAE,eAAe;IACxB,sDAAsD;aACtD,WAAW,EAAE,mBAAmB;IAChC,gEAAgE;aAChE,gBAAgB,EAAE,wBAAwB;IAC1C,wDAAwD;aACxD,aAAa,EAAE,qBAAqB;IACpC;;;;;;;;;;OAUG;aACH,mBAAmB,EAAE,2BAA2B;
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/audit/actions.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;IAC3B,+FAA+F;aAC/F,MAAM,EAAE,aAAa;IACrB,iDAAiD;aACjD,OAAO,EAAE,cAAc;IACvB,yFAAyF;aACzF,YAAY,EAAE,oBAAoB;IAClC,sHAAsH;aACtH,kBAAkB,EAAE,2BAA2B;IAC/C,4DAA4D;aAC5D,aAAa,EAAE,sBAAsB;IACrC,4DAA4D;aAC5D,OAAO,EAAE,eAAe;IACxB,sDAAsD;aACtD,WAAW,EAAE,mBAAmB;IAChC,gEAAgE;aAChE,gBAAgB,EAAE,wBAAwB;IAC1C,wDAAwD;aACxD,aAAa,EAAE,qBAAqB;IACpC;;;;;;;;;;OAUG;aACH,mBAAmB,EAAE,2BAA2B;IAChD;;;;;;;;;;OAUG;aACH,eAAe,EAAE,wBAAwB;IAEzC;;;;;;;;;;OAUG;IAEH,wGAAwG;aACxG,gBAAgB,EAAE,yBAAyB;IAC3C,sFAAsF;aACtF,aAAa,EAAE,sBAAsB;IACrC,kEAAkE;aAClE,kBAAkB,EAAE,2BAA2B;IAC/C,iEAAiE;aACjE,mBAAmB,EAAE,4BAA4B;IACjD,iGAAiG;aACjG,wBAAwB,EAAE,kCAAkC;IAC5D,wGAAwG;aACxG,kBAAkB,EAAE,2BAA2B;CACvC,CAAC;AAEX,0CAA0C;AAC1C,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC"}
|
package/dist/audit/actions.js
CHANGED
|
@@ -41,6 +41,18 @@ const AuthAuditActions = {
|
|
|
41
41
|
*/
|
|
42
42
|
providerUnavailable: "auth/provider_unavailable",
|
|
43
43
|
/**
|
|
44
|
+
* Somebody signed in tried to attach a social provider without having authenticated recently enough.
|
|
45
|
+
* Outcome `denied`, severity `warning`.
|
|
46
|
+
*
|
|
47
|
+
* Attaching an identity grants permanent access — after it, sign-in resolves by account id and the email
|
|
48
|
+
* stops mattering — so this is the row that answers "was somebody walking a stolen credential at the
|
|
49
|
+
* account-takeover step". One is a person who left a tab open; a run of them against one user id is the
|
|
50
|
+
* incident, and without the row there is nothing to count.
|
|
51
|
+
*
|
|
52
|
+
* Mirrors the error code, which is this file's one precedent for doing so.
|
|
53
|
+
*/
|
|
54
|
+
sessionNotFresh: "auth/session_not_fresh",
|
|
55
|
+
/**
|
|
44
56
|
* The admin actions, emitted only from the control-plane surface (`http/adminRoutes.ts`) and always
|
|
45
57
|
* with `actorType: "control-plane"` — a management client is not a user of the adopter's app, so its
|
|
46
58
|
* actions must be answerable separately from their users'.
|
package/dist/audit/emit.d.ts
CHANGED
|
@@ -94,6 +94,18 @@ export declare function emitProviderUnavailable(emit: AuditEmit, context: {
|
|
|
94
94
|
provider: string;
|
|
95
95
|
headers: Headers | undefined;
|
|
96
96
|
}): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Emit a `session_not_fresh` event — an attempt to attach a provider on an authentic but stale session.
|
|
99
|
+
*
|
|
100
|
+
* `actorType: "user"` rather than `anonymous`, unlike `emitProviderUnavailable`: this caller is
|
|
101
|
+
* authenticated, and the user id is the whole value of the row. Counting these per user is how a stolen
|
|
102
|
+
* credential being walked toward a link becomes visible.
|
|
103
|
+
*/
|
|
104
|
+
export declare function emitLinkSessionNotFresh(emit: AuditEmit, context: {
|
|
105
|
+
userId: string;
|
|
106
|
+
sessionId: string;
|
|
107
|
+
headers: Headers | undefined;
|
|
108
|
+
}): Promise<void>;
|
|
97
109
|
/** A blocked/failed auth attempt — recorded as `denied` (first-class). */
|
|
98
110
|
export declare function emitDenied(emit: AuditEmit, context: {
|
|
99
111
|
ip?: string;
|
package/dist/audit/emit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/audit/emit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAGnE;;;;;;;GAOG;AAEH,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAK7F;AAUD,uGAAuG;AACvG,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IAClF,aAAa,E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CAAC,CAAC;CACpC,GACA,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,SAAS,EACf,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,GAC1D,OAAO,CAAC,IAAI,CAAC,CASf;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,SAAS,EACf,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,GAC3E,OAAO,CAAC,IAAI,CAAC,CAYf;AAED,0EAA0E;AAC1E,wBAAsB,UAAU,CAC9B,IAAI,EAAE,SAAS,EACf,OAAO,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5D,OAAO,CAAC,IAAI,CAAC,CASf"}
|
package/dist/audit/emit.js
CHANGED
|
@@ -157,6 +157,24 @@ async function emitProviderUnavailable(emit, context) {
|
|
|
157
157
|
...correlation(context.headers)
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Emit a `session_not_fresh` event — an attempt to attach a provider on an authentic but stale session.
|
|
162
|
+
*
|
|
163
|
+
* `actorType: "user"` rather than `anonymous`, unlike `emitProviderUnavailable`: this caller is
|
|
164
|
+
* authenticated, and the user id is the whole value of the row. Counting these per user is how a stolen
|
|
165
|
+
* credential being walked toward a link becomes visible.
|
|
166
|
+
*/
|
|
167
|
+
async function emitLinkSessionNotFresh(emit, context) {
|
|
168
|
+
await safeEmit(emit, {
|
|
169
|
+
action: AuthAuditActions.sessionNotFresh,
|
|
170
|
+
outcome: "denied",
|
|
171
|
+
severity: "warning",
|
|
172
|
+
actorType: "user",
|
|
173
|
+
actorId: context.userId,
|
|
174
|
+
sessionId: context.sessionId,
|
|
175
|
+
...correlation(context.headers)
|
|
176
|
+
});
|
|
177
|
+
}
|
|
160
178
|
/** A blocked/failed auth attempt — recorded as `denied` (first-class). */
|
|
161
179
|
async function emitDenied(emit, context) {
|
|
162
180
|
await safeEmit(emit, {
|
|
@@ -169,4 +187,4 @@ async function emitDenied(emit, context) {
|
|
|
169
187
|
});
|
|
170
188
|
}
|
|
171
189
|
//#endregion
|
|
172
|
-
export { correlation, emitAfterRequest, emitControlPlaneAction, emitDenied, emitDeviceRevoked, emitProviderUnavailable, emitTokenRefresh, emitTokenReuseDetected };
|
|
190
|
+
export { correlation, emitAfterRequest, emitControlPlaneAction, emitDenied, emitDeviceRevoked, emitLinkSessionNotFresh, emitProviderUnavailable, emitTokenRefresh, emitTokenReuseDetected };
|
package/dist/capability.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { Capability } from "@pithy-sh/core/src/capability/capability";
|
|
|
4
4
|
import type { EmailCapability } from "@pithy-sh/email/src/capability";
|
|
5
5
|
import { type TurnstileMode } from "@pithy-sh/turnstile/src/config/config";
|
|
6
6
|
import { z } from "zod";
|
|
7
|
+
import type { GithubUserInfoResolver } from "./instance/githubUserInfo";
|
|
7
8
|
/** The auth capability's configuration — the thin surface an adopter owns in `pithy.config.ts`. */
|
|
8
9
|
export declare const AuthConfig: z.ZodObject<{
|
|
9
10
|
basePath: z.ZodDefault<z.ZodString>;
|
|
@@ -11,17 +12,21 @@ export declare const AuthConfig: z.ZodObject<{
|
|
|
11
12
|
trustedOrigins: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
12
13
|
database: z.ZodDefault<z.ZodString>;
|
|
13
14
|
rateLimiterBinding: z.ZodDefault<z.ZodString>;
|
|
14
|
-
google: z.
|
|
15
|
+
google: z.ZodPrefault<z.ZodObject<{
|
|
15
16
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
17
|
+
allowSignUp: z.ZodDefault<z.ZodBoolean>;
|
|
16
18
|
}, z.core.$strip>>;
|
|
17
|
-
apple: z.
|
|
19
|
+
apple: z.ZodPrefault<z.ZodObject<{
|
|
18
20
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
21
|
+
allowSignUp: z.ZodDefault<z.ZodBoolean>;
|
|
19
22
|
}, z.core.$strip>>;
|
|
20
|
-
facebook: z.
|
|
23
|
+
facebook: z.ZodPrefault<z.ZodObject<{
|
|
21
24
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
25
|
+
allowSignUp: z.ZodDefault<z.ZodBoolean>;
|
|
22
26
|
}, z.core.$strip>>;
|
|
23
|
-
github: z.
|
|
27
|
+
github: z.ZodPrefault<z.ZodObject<{
|
|
24
28
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
29
|
+
allowSignUp: z.ZodDefault<z.ZodBoolean>;
|
|
25
30
|
}, z.core.$strip>>;
|
|
26
31
|
sessionExpiresIn: z.ZodDefault<z.ZodNumber>;
|
|
27
32
|
sessionUpdateAge: z.ZodDefault<z.ZodNumber>;
|
|
@@ -39,6 +44,8 @@ export type AuthConfigInput = z.input<typeof AuthConfig>;
|
|
|
39
44
|
*/
|
|
40
45
|
export interface AuthWiring {
|
|
41
46
|
config: AuthConfig;
|
|
47
|
+
/** The adopter's GitHub identity resolver, or `undefined` for the kit's own rule. See {@link AuthOptions}. */
|
|
48
|
+
resolveGithubUserInfo: GithubUserInfoResolver | undefined;
|
|
42
49
|
/** The email capability's bound enqueue seam — how magic-link/OTP are delivered. Set by `compose`. */
|
|
43
50
|
enqueueEmail: EmailCapability["enqueue"] | undefined;
|
|
44
51
|
/** The turnstile login gate, when the turnstile capability is composed. Set by `compose`. */
|
|
@@ -46,6 +53,31 @@ export interface AuthWiring {
|
|
|
46
53
|
mode: TurnstileMode;
|
|
47
54
|
} | undefined;
|
|
48
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* What `auth()` takes: the config, plus the seams that are **behavior rather than data**.
|
|
58
|
+
*
|
|
59
|
+
* A function cannot live in the Zod schema — the schema is the self-documenting surface `pithy` renders
|
|
60
|
+
* and the config projection serializes, and neither can carry a closure. So the split follows
|
|
61
|
+
* `PaymentsOptions`: everything describable stays in {@link AuthConfig}, and a resolver is a sibling key
|
|
62
|
+
* destructured off before the parse.
|
|
63
|
+
*/
|
|
64
|
+
export type AuthOptions = AuthConfigInput & {
|
|
65
|
+
/**
|
|
66
|
+
* Resolve a GitHub identity yourself, replacing the kit's primary-only rule.
|
|
67
|
+
*
|
|
68
|
+
* The kit's default is deliberately conservative: it links on the **primary** address and nothing else,
|
|
69
|
+
* because GitHub never re-verifies and a verified secondary can only speak to the past. An adopter who
|
|
70
|
+
* wants a richer ladder — match a verified secondary, present a chooser on multiple matches — builds it
|
|
71
|
+
* here. `getUserInfo` is the only hook in this flow running before both fetches and before
|
|
72
|
+
* `mapProfileToUser`, and the only one holding the OAuth token.
|
|
73
|
+
*
|
|
74
|
+
* **Better Auth trusts what you return, verbatim.** It performs no independent check, so an
|
|
75
|
+
* `emailVerified: true` you did not read from GitHub is an account takeover: an attacker adds a
|
|
76
|
+
* victim's address to their own GitHub *unverified* and links to the victim's user. Return GitHub's
|
|
77
|
+
* real per-address flag, always.
|
|
78
|
+
*/
|
|
79
|
+
resolveGithubUserInfo?: GithubUserInfoResolver;
|
|
80
|
+
};
|
|
49
81
|
/** The auth capability, with its resolved config attached for inspection. */
|
|
50
82
|
export interface AuthCapability extends Capability {
|
|
51
83
|
authConfig: AuthConfig;
|
|
@@ -56,7 +88,7 @@ export interface AuthCapability extends Capability {
|
|
|
56
88
|
* `AuthContext` seam. Depends on `secrets` and `email`; auto-gates its send routes with `turnstile`
|
|
57
89
|
* and emits `auth/*` through `audit` when those are composed.
|
|
58
90
|
*/
|
|
59
|
-
export declare function auth(
|
|
91
|
+
export declare function auth(options: AuthOptions): AuthCapability;
|
|
60
92
|
/** Type guard: is this capability the auth capability? */
|
|
61
93
|
export declare function isAuthCapability(capability: Capability): capability is AuthCapability;
|
|
62
94
|
//# sourceMappingURL=capability.d.ts.map
|
package/dist/capability.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,0CAA0C,CAAC;AAG5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGtE,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACnG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,0CAA0C,CAAC;AAG5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGtE,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACnG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAmCxE,mGAAmG;AACnG,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsE8B,CAAC;AACtD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AACrD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEzD;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,UAAU,CAAC;IACnB,8GAA8G;IAC9G,qBAAqB,EAAE,sBAAsB,GAAG,SAAS,CAAC;IAC1D,sGAAsG;IACtG,YAAY,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IACrD,6FAA6F;IAC7F,SAAS,EAAE;QAAE,IAAI,EAAE,aAAa,CAAA;KAAE,GAAG,SAAS,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG;IAC1C;;;;;;;;;;;;;OAaG;IACH,qBAAqB,CAAC,EAAE,sBAAsB,CAAC;CAChD,CAAC;AAEF,6EAA6E;AAC7E,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,UAAU,EAAE,UAAU,CAAC;CACxB;AAiCD;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAyJzD;AAED,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,cAAc,CAErF"}
|
package/dist/capability.js
CHANGED
|
@@ -10,8 +10,9 @@ import { authAdminRoutes } from "./http/guards.js";
|
|
|
10
10
|
import { createSessionMiddleware } from "./http/middleware.js";
|
|
11
11
|
import { createRateLimitMiddleware } from "./http/rateLimit.js";
|
|
12
12
|
import { createAuthRoutes } from "./http/routes.js";
|
|
13
|
-
import
|
|
13
|
+
import "./migrations/0001_init.js";
|
|
14
14
|
import { authPluginPlan } from "./migrations/pluginTables.js";
|
|
15
|
+
import { AUTH_MIGRATIONS } from "./migrations/set.js";
|
|
15
16
|
import { authExampleSeed } from "./seeds/example.js";
|
|
16
17
|
import { PACKAGE_VERSION } from "./version.generated.js";
|
|
17
18
|
import { defineCapability } from "@pithy-sh/core/src/capability/capability";
|
|
@@ -21,8 +22,20 @@ import { isTurnstileCapability } from "@pithy-sh/turnstile/src/capability";
|
|
|
21
22
|
import { TURNSTILE_LOGIN_ACTION } from "@pithy-sh/turnstile/src/config/config";
|
|
22
23
|
import { z } from "zod";
|
|
23
24
|
//#region src/capability.ts
|
|
24
|
-
/**
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* A social provider toggle. Credentials live in the secrets store, never config.
|
|
27
|
+
*
|
|
28
|
+
* **Defaulted with `.prefault({})` rather than `.default({ enabled: false })`, and the difference is not
|
|
29
|
+
* cosmetic.** Zod 4 hands a `.default` value back verbatim without parsing it, so a literal supplied the
|
|
30
|
+
* object's *shape* while silently skipping every inner field default — `allowSignUp` was `undefined` on
|
|
31
|
+
* all four providers until a caller wrote one out by hand, which is precisely the field whose absence
|
|
32
|
+
* must not read as "false". `.prefault` runs the value through the schema, so one place states the
|
|
33
|
+
* defaults and nothing has to restate them.
|
|
34
|
+
*/
|
|
35
|
+
const ProviderToggle = z.object({
|
|
36
|
+
enabled: z.boolean().default(false).describe("Whether this social provider is enabled. Credentials are read from the secrets store, never config."),
|
|
37
|
+
allowSignUp: z.boolean().default(true).describe("Whether signing in with this provider may create a new account. When false, a sign-in whose email matches no existing user is refused and nothing is minted — the caller signs in by email first, then connects this provider from their profile. Separate from the top-level `disableSignUp`, which governs magic link and OTP.")
|
|
38
|
+
}).describe("A social provider's on/off toggle and its sign-up policy.");
|
|
26
39
|
/** The auth capability's configuration — the thin surface an adopter owns in `pithy.config.ts`. */
|
|
27
40
|
const AuthConfig = z.object({
|
|
28
41
|
basePath: z.string().default("/auth").describe("The path the auth handler mounts under. Must match the OAuth redirect URIs you register. Defaults to `/auth`."),
|
|
@@ -30,10 +43,10 @@ const AuthConfig = z.object({
|
|
|
30
43
|
trustedOrigins: z.array(z.string()).default([]).describe("Web origins and mobile deep-link schemes allowed as redirect targets and for cookie CSRF origin checks (e.g. `https://app.example.com`, `myapp://`)."),
|
|
31
44
|
database: z.string().default("DB").describe("The D1 binding the auth tables and migrations target. Defaults to `DB`, the shared app database."),
|
|
32
45
|
rateLimiterBinding: z.string().default("AUTH_RATE_LIMITER").describe("The Workers Rate Limiting binding for the coarse per-IP edge guard on the auth routes (tier 1). Its limit and window are set on the binding in wrangler.jsonc. Complements Better Auth's per-action limiter (tier 2)."),
|
|
33
|
-
google: ProviderToggle.
|
|
34
|
-
apple: ProviderToggle.
|
|
35
|
-
facebook: ProviderToggle.
|
|
36
|
-
github: ProviderToggle.
|
|
46
|
+
google: ProviderToggle.prefault({}).describe("Google OAuth. Enable it, then store credentials as the `auth-google-credentials` secret. See docs/google-oauth.md."),
|
|
47
|
+
apple: ProviderToggle.prefault({}).describe("Apple Sign-In. Enable it, then store credentials as the `auth-apple-credentials` secret. See docs/apple-signin.md."),
|
|
48
|
+
facebook: ProviderToggle.prefault({}).describe("Facebook Login. Enable it, then store credentials as the `auth-facebook-credentials` secret. See docs/facebook-oauth.md."),
|
|
49
|
+
github: ProviderToggle.prefault({}).describe("GitHub OAuth. Enable it, then store credentials as the `auth-github-credentials` secret. See docs/github-oauth.md."),
|
|
37
50
|
sessionExpiresIn: z.number().int().default(604800).describe("Session (refresh credential) lifetime in seconds. Defaults to 7 days. Expiry slides forward on use."),
|
|
38
51
|
sessionUpdateAge: z.number().int().default(86400).describe("How often (seconds) an active session's expiry slides forward. Defaults to 1 day."),
|
|
39
52
|
verificationExpiresIn: z.number().int().default(300).describe("Magic-link and OTP lifetime in seconds. Defaults to 5 minutes. Single-use regardless."),
|
|
@@ -71,12 +84,14 @@ function assertPluginTablesUnclaimed(capabilities, binding, extensions) {
|
|
|
71
84
|
* `AuthContext` seam. Depends on `secrets` and `email`; auto-gates its send routes with `turnstile`
|
|
72
85
|
* and emits `auth/*` through `audit` when those are composed.
|
|
73
86
|
*/
|
|
74
|
-
function auth(
|
|
87
|
+
function auth(options) {
|
|
88
|
+
const { resolveGithubUserInfo, ...config } = options;
|
|
75
89
|
const resolved = AuthConfig.parse(config);
|
|
76
90
|
assertAdditivePlugins(resolved.plugins);
|
|
77
91
|
const pluginPlan = authPluginPlan(resolved.plugins);
|
|
78
92
|
const wiring = {
|
|
79
93
|
config: resolved,
|
|
94
|
+
resolveGithubUserInfo,
|
|
80
95
|
enqueueEmail: void 0,
|
|
81
96
|
turnstile: void 0
|
|
82
97
|
};
|
|
@@ -107,7 +122,7 @@ function auth(config) {
|
|
|
107
122
|
tables: authTables,
|
|
108
123
|
migrationOrder: 300,
|
|
109
124
|
migrations: {
|
|
110
|
-
|
|
125
|
+
...AUTH_MIGRATIONS,
|
|
111
126
|
...pluginPlan.migrations
|
|
112
127
|
}
|
|
113
128
|
} },
|
|
@@ -147,6 +162,12 @@ function auth(config) {
|
|
|
147
162
|
facebook: resolved.facebook.enabled,
|
|
148
163
|
github: resolved.github.enabled
|
|
149
164
|
},
|
|
165
|
+
providerSignUp: {
|
|
166
|
+
google: resolved.google.allowSignUp,
|
|
167
|
+
apple: resolved.apple.allowSignUp,
|
|
168
|
+
facebook: resolved.facebook.allowSignUp,
|
|
169
|
+
github: resolved.github.allowSignUp
|
|
170
|
+
},
|
|
150
171
|
otpLength: resolved.otpLength,
|
|
151
172
|
signUpEnabled: !resolved.disableSignUp
|
|
152
173
|
}),
|
package/dist/client/api.d.ts
CHANGED
|
@@ -293,9 +293,17 @@ export type SocialSignIn = {
|
|
|
293
293
|
* **No humanity check, deliberately**: the redirect carries no token to check and the provider runs its
|
|
294
294
|
* own bot defense, which is what `@pithy-sh/auth` already assumes when it stacks the check on the
|
|
295
295
|
* magic-link route alone. Gating it would only stop people signing in.
|
|
296
|
+
*
|
|
297
|
+
* **`errorCallbackURL` is how a refusal gets back to a screen at all.** Absent it, Better Auth sends a
|
|
298
|
+
* refused callback to `${baseURL}${basePath}/error`, which in production redirects on to the adopter's
|
|
299
|
+
* home route carrying a query string no template reads — so the user lands on a page that says nothing
|
|
300
|
+
* about what just happened. Pass the sign-in screen's own path and the refusal returns to the control
|
|
301
|
+
* that started it, as `?error=<code>`. That is the transport the whole GitHub rejection copy depends on
|
|
302
|
+
* (pithy-sh/pithy#554); without it the sentence exists and is unreachable.
|
|
296
303
|
*/
|
|
297
304
|
export declare function startSocialSignIn(input: {
|
|
298
305
|
provider: string;
|
|
299
306
|
callbackURL: string;
|
|
307
|
+
errorCallbackURL?: string;
|
|
300
308
|
}, options?: AuthClientOptions): Promise<SocialSignIn>;
|
|
301
309
|
//# sourceMappingURL=api.d.ts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M,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACrC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,EACzC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EAC7C,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAE9C;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AA0B9C;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,EAC3E,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAOvB"}
|
package/dist/client/api.js
CHANGED
|
@@ -367,6 +367,13 @@ function isAuthorization(value) {
|
|
|
367
367
|
* **No humanity check, deliberately**: the redirect carries no token to check and the provider runs its
|
|
368
368
|
* own bot defense, which is what `@pithy-sh/auth` already assumes when it stacks the check on the
|
|
369
369
|
* magic-link route alone. Gating it would only stop people signing in.
|
|
370
|
+
*
|
|
371
|
+
* **`errorCallbackURL` is how a refusal gets back to a screen at all.** Absent it, Better Auth sends a
|
|
372
|
+
* refused callback to `${baseURL}${basePath}/error`, which in production redirects on to the adopter's
|
|
373
|
+
* home route carrying a query string no template reads — so the user lands on a page that says nothing
|
|
374
|
+
* about what just happened. Pass the sign-in screen's own path and the refusal returns to the control
|
|
375
|
+
* that started it, as `?error=<code>`. That is the transport the whole GitHub rejection copy depends on
|
|
376
|
+
* (pithy-sh/pithy#554); without it the sentence exists and is unreachable.
|
|
370
377
|
*/
|
|
371
378
|
async function startSocialSignIn(input, options) {
|
|
372
379
|
const ungated = options && {
|
|
@@ -45,6 +45,28 @@ export type AuthClientProjection = {
|
|
|
45
45
|
/** Whether Sign in with GitHub is offered. */
|
|
46
46
|
github: boolean;
|
|
47
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Whether each offered provider may create an account, from its `allowSignUp` toggle.
|
|
50
|
+
*
|
|
51
|
+
* **A second fact from {@link signUpEnabled}, and the screen needs both.** That one answers for
|
|
52
|
+
* magic link and OTP; this answers per provider. A project can let email create accounts while
|
|
53
|
+
* GitHub only signs existing ones in — which is the configuration #554 exists for — and with only
|
|
54
|
+
* the global flag a screen renders "Signing in creates one." directly beneath a button that will
|
|
55
|
+
* refuse (#559).
|
|
56
|
+
*
|
|
57
|
+
* Optional, so a screen copied before this landed keeps compiling and reads `undefined` as "no
|
|
58
|
+
* provider objects" — the state every project was in until now.
|
|
59
|
+
*/
|
|
60
|
+
providerSignUp?: {
|
|
61
|
+
/** Whether a Google sign-in may create an account. */
|
|
62
|
+
google: boolean;
|
|
63
|
+
/** Whether an Apple sign-in may create an account. */
|
|
64
|
+
apple: boolean;
|
|
65
|
+
/** Whether a Facebook sign-in may create an account. */
|
|
66
|
+
facebook: boolean;
|
|
67
|
+
/** Whether a GitHub sign-in may create an account. */
|
|
68
|
+
github: boolean;
|
|
69
|
+
};
|
|
48
70
|
/** How many digits an email OTP carries. */
|
|
49
71
|
otpLength: number;
|
|
50
72
|
/** Whether signing in may provision a new user. Drives the sign-up copy. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../src/client/projection.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IACE,mGAAmG;IACnG,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,uCAAuC;IACvC,OAAO,EAAE,IAAI,CAAC;IACd,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;;OAOG;IACH,SAAS,EAAE;QACT,8CAA8C;QAC9C,MAAM,EAAE,OAAO,CAAC;QAChB,6CAA6C;QAC7C,KAAK,EAAE,OAAO,CAAC;QACf,gDAAgD;QAChD,QAAQ,EAAE,OAAO,CAAC;QAClB,8CAA8C;QAC9C,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;IACF,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC"}
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../src/client/projection.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IACE,mGAAmG;IACnG,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,uCAAuC;IACvC,OAAO,EAAE,IAAI,CAAC;IACd,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;;OAOG;IACH,SAAS,EAAE;QACT,8CAA8C;QAC9C,MAAM,EAAE,OAAO,CAAC;QAChB,6CAA6C;QAC7C,KAAK,EAAE,OAAO,CAAC;QACf,gDAAgD;QAChD,QAAQ,EAAE,OAAO,CAAC;QAClB,8CAA8C;QAC9C,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;IACF;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE;QACf,sDAAsD;QACtD,MAAM,EAAE,OAAO,CAAC;QAChB,sDAAsD;QACtD,KAAK,EAAE,OAAO,CAAC;QACf,wDAAwD;QACxD,QAAQ,EAAE,OAAO,CAAC;QAClB,sDAAsD;QACtD,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;IACF,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC"}
|
|
@@ -25,6 +25,7 @@ export declare const Session: z.ZodObject<{
|
|
|
25
25
|
userId: z.ZodString;
|
|
26
26
|
deviceId: z.ZodNullable<z.ZodString>;
|
|
27
27
|
familyId: z.ZodNullable<z.ZodString>;
|
|
28
|
+
authenticatedAt: z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>;
|
|
28
29
|
}, z.core.$strip>;
|
|
29
30
|
export type Session = z.output<typeof Session>;
|
|
30
31
|
/** `pithy_auth_accounts` — a credential/identity link for a user (one row per social provider). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"betterAuth.d.ts","sourceRoot":"","sources":["../../src/data/betterAuth.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuBxB,2FAA2F;AAC3F,eAAO,MAAM,IAAI;;;;;;;;;iBAqBwF,CAAC;AAC1G,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC;AAEzC,6FAA6F;AAC7F,eAAO,MAAM,OAAO
|
|
1
|
+
{"version":3,"file":"betterAuth.d.ts","sourceRoot":"","sources":["../../src/data/betterAuth.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuBxB,2FAA2F;AAC3F,eAAO,MAAM,IAAI;;;;;;;;;iBAqBwF,CAAC;AAC1G,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC;AAEzC,6FAA6F;AAC7F,eAAO,MAAM,OAAO;;;;;;;;;;;;iBAqCqF,CAAC;AAC1G,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,OAAO,CAAC,CAAC;AAE/C,mGAAmG;AACnG,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;iBAyCqF,CAAC;AAC1G,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,OAAO,CAAC,CAAC;AAE/C,8FAA8F;AAC9F,eAAO,MAAM,YAAY;;;;;;;iBAmBtB,CAAC;AACJ,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEzD,gGAAgG;AAChG,eAAO,MAAM,IAAI;;;;;;;;iBA8Bd,CAAC;AACJ,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC;AAEzC,sHAAsH;AACtH,eAAO,MAAM,SAAS;;;;;iBAcnB,CAAC;AACJ,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
package/dist/data/betterAuth.js
CHANGED
|
@@ -45,7 +45,8 @@ const Session = z.object({
|
|
|
45
45
|
userAgent: z.string().nullable().describe("The client user-agent at sign-in. Nullable."),
|
|
46
46
|
userId: z.string().describe("The owning user's id. Foreign key to `pithy_auth_users(id)`, ON DELETE CASCADE."),
|
|
47
47
|
deviceId: z.string().nullable().describe("The id of the `pithy_auth_devices` row this session is bound to (per-device sessions), or null for a device-less web login."),
|
|
48
|
-
familyId: z.string().nullable().describe("The refresh-token family this session belongs to, carried across rotations so a replayed refresh token can revoke the whole chain. Server-set; null for a session created before rotation or one never rotated.")
|
|
48
|
+
familyId: z.string().nullable().describe("The refresh-token family this session belongs to, carried across rotations so a replayed refresh token can revoke the whole chain. Server-set; null for a session created before rotation or one never rotated."),
|
|
49
|
+
authenticatedAt: BetterAuthDate.nullable().describe("When the holder of this session last actually authenticated — a sign-in, never a rotation, which carries the value forward unchanged. This is what the provider-linking freshness gate reads; the session's own `createdAt` cannot be, because `/token/rotate` stamps a fresh one on every successor and is therefore resettable by anyone holding a stolen refresh token (#558). ISO-8601 text in SQLite. Null only for a session written before the column existed.")
|
|
49
50
|
}).describe("A session in `pithy_auth_sessions` — a signed-in credential, optionally bound to a device.");
|
|
50
51
|
/** `pithy_auth_accounts` — a credential/identity link for a user (one row per social provider). */
|
|
51
52
|
const Account = z.object({
|
package/dist/data/kitFields.d.ts
CHANGED
|
@@ -59,10 +59,27 @@ export declare const KIT_USER_FIELDS: {
|
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
|
+
* **`authenticatedAt` carries three decisions a future author must not undo.**
|
|
63
|
+
*
|
|
64
|
+
* `type: "date"` rather than `"string"`: the adapter's `Date` ↔ ISO-8601 conversion is keyed on that
|
|
65
|
+
* literal (`@better-auth/core`'s `factory.mjs`, on write and on read), and the kysely adapter reports
|
|
66
|
+
* `supportsDates: false` for SQLite. `deviceId`/`familyId` are `"string"` because they are opaque ids; a
|
|
67
|
+
* timestamp is not.
|
|
68
|
+
*
|
|
69
|
+
* **No `defaultValue`, and this is the one that bites.** A function default would stamp every sign-in
|
|
70
|
+
* with no hook at all — but `getSessionDefaultFields` is spread into the row *after* the caller's
|
|
71
|
+
* override in `createSession`, so a fresh default would overwrite the value `rotateToken` carries
|
|
72
|
+
* forward, silently restoring the exact defect this column exists to fix (#558). It is stamped by the
|
|
73
|
+
* `session.create.before` hook instead.
|
|
74
|
+
*
|
|
75
|
+
* `input: false`, like its siblings: a client able to name its own authentication time would defeat the
|
|
76
|
+
* link-freshness gate outright. `required: false` because the column is nullable for rows written before
|
|
77
|
+
* it existed.
|
|
78
|
+
*
|
|
62
79
|
* The extra `pithy_auth_sessions` columns — the bound device, and the refresh-token family carried
|
|
63
80
|
* across rotations.
|
|
64
81
|
*
|
|
65
|
-
* `input: false` on
|
|
82
|
+
* `input: false` on all three: these are server-set facts about a session, and a client able to name its own
|
|
66
83
|
* device id or token family could name somebody else's.
|
|
67
84
|
*/
|
|
68
85
|
export declare const KIT_SESSION_FIELDS: {
|
|
@@ -76,5 +93,10 @@ export declare const KIT_SESSION_FIELDS: {
|
|
|
76
93
|
readonly required: false;
|
|
77
94
|
readonly input: false;
|
|
78
95
|
};
|
|
96
|
+
readonly authenticatedAt: {
|
|
97
|
+
readonly type: "date";
|
|
98
|
+
readonly required: false;
|
|
99
|
+
readonly input: false;
|
|
100
|
+
};
|
|
79
101
|
};
|
|
80
102
|
//# sourceMappingURL=kitFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kitFields.d.ts","sourceRoot":"","sources":["../../src/data/kitFields.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,eAAe;aAC1B,MAAM;iBAAI,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;iBAAQ,SAAS;qBAAI,KAAK;;;CAClE,CAAC;AAEX
|
|
1
|
+
{"version":3,"file":"kitFields.d.ts","sourceRoot":"","sources":["../../src/data/kitFields.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,eAAe;aAC1B,MAAM;iBAAI,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;iBAAQ,SAAS;qBAAI,KAAK;;;CAClE,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,kBAAkB;aAC7B,QAAQ;iBAAI,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;;aAClD,QAAQ;iBAAI,IAAI,EAAE,QAAQ;iBAAE,QAAQ;iBAAS,KAAK;;aAClD,eAAe;iBAAI,IAAI,EAAE,MAAM;iBAAE,QAAQ;iBAAS,KAAK;;CAC/C,CAAC"}
|
package/dist/data/kitFields.js
CHANGED
|
@@ -57,10 +57,27 @@ const KIT_USER_FIELDS = { locale: {
|
|
|
57
57
|
validator: { input: Locale.nullable() }
|
|
58
58
|
} };
|
|
59
59
|
/**
|
|
60
|
+
* **`authenticatedAt` carries three decisions a future author must not undo.**
|
|
61
|
+
*
|
|
62
|
+
* `type: "date"` rather than `"string"`: the adapter's `Date` ↔ ISO-8601 conversion is keyed on that
|
|
63
|
+
* literal (`@better-auth/core`'s `factory.mjs`, on write and on read), and the kysely adapter reports
|
|
64
|
+
* `supportsDates: false` for SQLite. `deviceId`/`familyId` are `"string"` because they are opaque ids; a
|
|
65
|
+
* timestamp is not.
|
|
66
|
+
*
|
|
67
|
+
* **No `defaultValue`, and this is the one that bites.** A function default would stamp every sign-in
|
|
68
|
+
* with no hook at all — but `getSessionDefaultFields` is spread into the row *after* the caller's
|
|
69
|
+
* override in `createSession`, so a fresh default would overwrite the value `rotateToken` carries
|
|
70
|
+
* forward, silently restoring the exact defect this column exists to fix (#558). It is stamped by the
|
|
71
|
+
* `session.create.before` hook instead.
|
|
72
|
+
*
|
|
73
|
+
* `input: false`, like its siblings: a client able to name its own authentication time would defeat the
|
|
74
|
+
* link-freshness gate outright. `required: false` because the column is nullable for rows written before
|
|
75
|
+
* it existed.
|
|
76
|
+
*
|
|
60
77
|
* The extra `pithy_auth_sessions` columns — the bound device, and the refresh-token family carried
|
|
61
78
|
* across rotations.
|
|
62
79
|
*
|
|
63
|
-
* `input: false` on
|
|
80
|
+
* `input: false` on all three: these are server-set facts about a session, and a client able to name its own
|
|
64
81
|
* device id or token family could name somebody else's.
|
|
65
82
|
*/
|
|
66
83
|
const KIT_SESSION_FIELDS = {
|
|
@@ -73,6 +90,11 @@ const KIT_SESSION_FIELDS = {
|
|
|
73
90
|
type: "string",
|
|
74
91
|
required: false,
|
|
75
92
|
input: false
|
|
93
|
+
},
|
|
94
|
+
authenticatedAt: {
|
|
95
|
+
type: "date",
|
|
96
|
+
required: false,
|
|
97
|
+
input: false
|
|
76
98
|
}
|
|
77
99
|
};
|
|
78
100
|
//#endregion
|
package/dist/data/tables.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare const authTables: {
|
|
|
34
34
|
userId: import("zod").ZodString;
|
|
35
35
|
deviceId: import("zod").ZodNullable<import("zod").ZodString>;
|
|
36
36
|
familyId: import("zod").ZodNullable<import("zod").ZodString>;
|
|
37
|
+
authenticatedAt: import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodDate]>, import("zod").ZodDate>>;
|
|
37
38
|
}, import("zod/v4/core").$strip>;
|
|
38
39
|
pithyAuthAccounts: import("zod").ZodObject<{
|
|
39
40
|
id: import("zod").ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/data/tables.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKrC;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU;IACrB,cAAc;;;;;;;;;;IACd,iBAAiB
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/data/tables.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKrC;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU;IACrB,cAAc;;;;;;;;;;IACd,iBAAiB;;;;;;;;;;;;;IACjB,iBAAiB;;;;;;;;;;;;;;;;IACjB,sBAAsB;;;;;;;;IACtB,aAAa;;;;;;;;;IACb,kBAAkB;;;;;;IAClB,gBAAgB;;;;;;;;;;;;;;;;;IAChB,sBAAsB;;;;;;CACvB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC;AAE3C,8GAA8G;AAC9G,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;AAE9D,yGAAyG;AACzG,wBAAgB,YAAY,CAAC,EAAE,EAAE,UAAU,GAAG,YAAY,CAEzD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* **What pays for `allowDifferentEmails`.**
|
|
5
|
+
*
|
|
6
|
+
* A signed-in user may attach a provider whose email differs from their own. That is the right behavior
|
|
7
|
+
* and it widens something: before it, a provider could only be linked to an account holding the same
|
|
8
|
+
* address, so a link was self-limiting. After it, a link is a decision the session alone authorizes.
|
|
9
|
+
*
|
|
10
|
+
* And Better Auth guards that decision **less** than it guards undoing it. Read the two endpoints beside
|
|
11
|
+
* each other in `better-auth/dist/api/routes/account.mjs`: `/link-social` takes `use: [sessionMiddleware]`
|
|
12
|
+
* — any session, any age — while `/unlink-account` takes `use: [freshSessionMiddleware]`. Attaching an
|
|
13
|
+
* identity grants *permanent* access, because once linked a sign-in resolves by account id and the email
|
|
14
|
+
* stops mattering; detaching one does not. The cheaper-guarded operation is the more powerful one.
|
|
15
|
+
*
|
|
16
|
+
* **It reads `authenticatedAt`, not the session's `createdAt`, and that distinction is the whole of #558.**
|
|
17
|
+
* The first version of this gate read session age. `/token/rotate` stamps a successor's `createdAt` with
|
|
18
|
+
* the moment of the call, so session age is reset by every rotation — ordinary on the bearer path, and
|
|
19
|
+
* available on demand to anyone holding a stolen refresh token. Two requests and the gate was open. The
|
|
20
|
+
* question it means to ask is how recently the *person* authenticated, which is a different fact, stamped
|
|
21
|
+
* once at sign-in and carried across rotations verbatim.
|
|
22
|
+
*
|
|
23
|
+
* **Not a Better Auth hook, and that is a framework constraint rather than a preference.** A `before` hook
|
|
24
|
+
* runs ahead of the endpoint's own `sessionMiddleware`, so `ctx.context.session` is null at hook time; and
|
|
25
|
+
* `runBeforeHooks` accumulates each hook's context changes and applies them only after *every* hook, so
|
|
26
|
+
* `bearer()`'s rewrite of `Authorization` into the session cookie never reaches a sibling hook either. A
|
|
27
|
+
* hook therefore cannot resolve a mobile caller's session at all, and a gate that cannot read a session
|
|
28
|
+
* refuses everyone — indistinguishable from the feature being broken, which invites deleting the gate.
|
|
29
|
+
*
|
|
30
|
+
* Provider-agnostic on purpose. Google and Apple are trusted providers, which makes them *more* exposed
|
|
31
|
+
* to this, not less: the question is how recently the caller proved they hold the account.
|
|
32
|
+
*/
|
|
33
|
+
import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
|
|
34
|
+
import { PithyError } from "@pithy-sh/core/src/error/pithyError";
|
|
35
|
+
import type { MiddlewareHandler } from "hono";
|
|
36
|
+
/**
|
|
37
|
+
* How recently the caller must have authenticated to attach a provider: **fifteen minutes.**
|
|
38
|
+
*
|
|
39
|
+
* Stated rather than inherited. Better Auth's `freshAge` default is 24 hours, which is the wrong order of
|
|
40
|
+
* magnitude here — a day-old authentication is not evidence that the person at the keyboard holds the
|
|
41
|
+
* account, and the whole exposure is a credential valid for days. Fifteen minutes covers an OAuth round
|
|
42
|
+
* trip that involves signing in to the provider first, and is short enough that a stolen credential is
|
|
43
|
+
* unlikely to still be inside the window.
|
|
44
|
+
*
|
|
45
|
+
* The cost of being wrong is one re-authentication — exactly what `/unlink-account` already charges for
|
|
46
|
+
* the smaller decision.
|
|
47
|
+
*/
|
|
48
|
+
export declare const LINK_FRESH_AGE_SECONDS: number;
|
|
49
|
+
/**
|
|
50
|
+
* Whether an authentication is recent enough to authorize attaching a provider.
|
|
51
|
+
*
|
|
52
|
+
* **Fails closed on anything it cannot read.** An absent, unparseable or future timestamp is not evidence
|
|
53
|
+
* of a recent authentication — it is the absence of evidence — and a gate that reads "I cannot tell" as
|
|
54
|
+
* "fresh" is one a row written before the column walks straight through. The future case matters as much
|
|
55
|
+
* as the past: a window checked on one side only would pass any future value forever.
|
|
56
|
+
*/
|
|
57
|
+
export declare function authenticationIsFresh(authenticatedAt: Date | string | null | undefined, now: Date): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The gate, as Hono middleware on the kit's own route tree.
|
|
60
|
+
*
|
|
61
|
+
* **A pure read of `c.var.auth`.** `createSessionMiddleware` has already resolved this request's
|
|
62
|
+
* credential — core registers every capability's middleware before any capability's routes — so resolving
|
|
63
|
+
* it again would be a second D1 round trip for a fact the seam is holding. That is the argument
|
|
64
|
+
* `AuthContext` already makes for `locale`.
|
|
65
|
+
*
|
|
66
|
+
* **No credential at all is 401, not this 403.** `auth/session_not_fresh` means "signed in, but not
|
|
67
|
+
* recently enough"; a caller holding nothing cannot tell that from "not signed in" and will not know
|
|
68
|
+
* whether to re-authenticate or to retry. The refusal is `requireAuth()`'s, word for word, so the two
|
|
69
|
+
* surfaces answer an absent credential identically.
|
|
70
|
+
*
|
|
71
|
+
* **Recorded before the throw**, like `emitProviderUnavailable`: one refusal is somebody who left a tab
|
|
72
|
+
* open, and a run of them against one user id is the incident. The trail has to hold it whether or not
|
|
73
|
+
* anything logs the refusal.
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* The refusal for attaching a provider without having authenticated recently.
|
|
77
|
+
*
|
|
78
|
+
* **Not `auth/forbidden`.** A client has to render this differently from every other 403, because the
|
|
79
|
+
* remedy is specific and cheap — sign in again, then retry — and a generic "you are not allowed" sends
|
|
80
|
+
* somebody to ask for a permission they already hold. `http/linkFreshness.ts` carries the argument for
|
|
81
|
+
* the gate itself.
|
|
82
|
+
*
|
|
83
|
+
* `message` says nothing was changed, because the caller is mid-flow and cannot otherwise tell whether
|
|
84
|
+
* the link half-happened.
|
|
85
|
+
*/
|
|
86
|
+
export declare function sessionNotFresh(): PithyError;
|
|
87
|
+
export declare function requireFreshAuthenticationToLink(now?: () => Date): MiddlewareHandler<PithyHonoEnv>;
|
|
88
|
+
//# sourceMappingURL=linkFreshness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linkFreshness.d.ts","sourceRoot":"","sources":["../../src/http/linkFreshness.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAqB,MAAM,qCAAqC,CAAC;AACpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAG9C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,QAAU,CAAC;AAE9C;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,IAAI,GAAG,OAAO,CAQ3G;AAED;;;;;;;;;;;;;;;;GAgBG;AACH;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,IAAI,UAAU,CAS5C;AAED,wBAAgB,gCAAgC,CAAC,GAAG,GAAE,MAAM,IAAuB,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAmBpH"}
|