ovr 7.0.0-next.15 → 7.0.0-next.16

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # ovr
2
2
 
3
+ ## 7.0.0-next.16
4
+
5
+ ### Minor Changes
6
+
7
+ - 9d8f561: - A passkey has what tells it apart in a list: `created`, the `origin` it was made at, and a `name`, which the `Add` form takes as an optional field.
8
+ - `auth.link(user, { origin, minutes })` makes a link that signs a user in once, for an origin where they have no passkey or after losing their device. It opens the authentication `page`, where `<Link />` from `auth.forms(c)` is the button that signs them in. Only the link's hash is stored, in the new `auth_links` table.
9
+ - `auth:1` changed for these, since v7 is not released: `auth_credentials` has three more columns and `auth_links` is new. A database migrated with an earlier prerelease needs the same changes made by hand, and the migration's checksum updated.
10
+
3
11
  ## 7.0.0-next.15
4
12
 
5
13
  ### Minor Changes
@@ -10,21 +10,30 @@ import type { Storage } from "./storage.js";
10
10
  */
11
11
  export declare function configure<U extends Auth.Users>(options: Auth.Options<U>, storage: Storage, state: (c: State.Context) => State): {
12
12
  routes: (Route.Used<Route.Get<"/_passkey/client.js", {}, Field.Shape>> | Route.Used<Route.Post<"/_passkey/options/add", {}, {
13
+ name: Field.Instance<string | undefined, "input", "text", undefined, undefined, undefined>;
13
14
  bootstrap: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
14
15
  }>> | Route.Used<Route.Post<"/_passkey/options/login", {}, {
15
16
  bootstrap: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
16
17
  }>> | Route.Used<Route.Post<"/_passkey/options/register", {}, {
17
18
  bootstrap: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
19
+ }>> | Route.Used<Route.Post<"/auth/link", {}, {
20
+ link: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
18
21
  }>> | Route.Used<Route.Post<"/auth/login", {}, {
19
22
  credential: Field.Instance<unknown, "input", "hidden", undefined, undefined, undefined>;
20
23
  ceremony: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
21
24
  }>> | Route.Used<Route.Post<"/auth/logout", {}, Field.Shape>> | Route.Used<Route.Post<"/auth/passkey", {}, {
22
25
  credential: Field.Instance<unknown, "input", "hidden", undefined, undefined, undefined>;
23
26
  ceremony: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
27
+ name: Field.Instance<string | undefined, "input", "text", undefined, undefined, undefined>;
24
28
  }>> | Route.Used<Route.Post<"/auth/register", {}, {
25
29
  credential: Field.Instance<unknown, "input", "hidden", undefined, undefined, undefined>;
26
30
  ceremony: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
27
31
  }>>)[];
32
+ /** Make a link that signs a user in once, see `Auth.link`. */
33
+ link(user: string, { origin, minutes, }?: {
34
+ origin?: string;
35
+ minutes?: number;
36
+ }): Promise<string>;
28
37
  /** Create forms in the handler before returning JSX, so ovr can set the binding cookie. */
29
38
  forms(c: Auth.Context, props?: {
30
39
  nonce?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../src/auth/configure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAsB,MAAM,kBAAkB,CAAC;AAI7D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,CAAC,KAAK,EAC7C,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EACxB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,KAAK,KAAK;;;;;;;;;;;;;;;;;IA+RjC,2FAA2F;aAEvF,IAAI,CAAC,OAAO,UACR;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GACvB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;EA6D9B"}
1
+ {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../src/auth/configure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAsB,MAAM,kBAAkB,CAAC;AAI7D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,CAAC,KAAK,EAC7C,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EACxB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,KAAK,KAAK;;;;;;;;;;;;;;;;;;;;;IA8TjC,8DAA8D;eAEvD,MAAM,yBAIT;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAiBzC,2FAA2F;aAEvF,IAAI,CAAC,OAAO,UACR;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GACvB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;EAqF9B"}
@@ -6,6 +6,7 @@ import { Route } from "../route/index.js";
6
6
  import { Header, Time, noStore } from "../util/index.js";
7
7
  import { Issue } from "./issue.js";
8
8
  import { Passkey } from "./passkey.js";
9
+ import { Token } from "./token.js";
9
10
  /**
10
11
  * Construct startup-complete handlers and request-scoped UI components.
11
12
  *
@@ -36,6 +37,7 @@ export function configure(options, storage, state) {
36
37
  login: "/auth/login",
37
38
  logout: "/auth/logout",
38
39
  passkey: "/auth/passkey",
40
+ link: "/auth/link",
39
41
  options: "/_passkey/options",
40
42
  };
41
43
  const page = options.page ?? "/login";
@@ -86,7 +88,8 @@ export function configure(options, storage, state) {
86
88
  c.redirect(target, 303);
87
89
  };
88
90
  const admit = async (c, method, prompt) => {
89
- const admission = await limits[method].check(c, prompt ? "options" : "verify");
91
+ // a link signs in, so it shares a login's limit
92
+ const admission = await limits[method === "link" ? "login" : method].check(c, prompt ? "options" : "verify");
90
93
  if (admission === true)
91
94
  return true;
92
95
  const now = Date.now();
@@ -213,10 +216,19 @@ export function configure(options, storage, state) {
213
216
  action: paths.login,
214
217
  });
215
218
  });
219
+ /** What a person calls a passkey they add, such as "Laptop" */
220
+ const naming = {
221
+ name: Field.text()
222
+ .max(64)
223
+ .optional()
224
+ .label("Name")
225
+ .hint("Such as the device it is on"),
226
+ };
216
227
  const add = Route.post(paths.passkey)
217
- .fields(Passkey.shape)
228
+ .fields({ ...naming, ...Passkey.shape })
218
229
  .use(guard("add"), async (c) => {
219
- if (!(await Issue.data(c)))
230
+ const input = await Issue.data(c);
231
+ if (!input || input.issues)
220
232
  throw new Issue("passkey request");
221
233
  const session = await state(c).session();
222
234
  if (!session)
@@ -226,7 +238,10 @@ export function configure(options, storage, state) {
226
238
  if (credential.user !== session.user)
227
239
  throw new Issue("user");
228
240
  await storage
229
- .register(() => { }, credential)
241
+ .register(() => { }, {
242
+ ...credential,
243
+ name: input.data.name?.trim() || null,
244
+ })
230
245
  .catch((error) => {
231
246
  // a passkey that is already an account's
232
247
  if (Database.unique(error))
@@ -236,7 +251,8 @@ export function configure(options, storage, state) {
236
251
  c.redirect(returning(c), 303);
237
252
  });
238
253
  const adding = Route.post(`${paths.options}/add`)
239
- .fields({ bootstrap: Field.hidden() })
254
+ // the form's own field is sent with it, and saved when it submits
255
+ .fields({ ...naming, bootstrap: Field.hidden() })
240
256
  .use(guard("add", true), async (c) => {
241
257
  const input = await Issue.data(c);
242
258
  if (!input || input.issues)
@@ -254,11 +270,26 @@ export function configure(options, storage, state) {
254
270
  exclude: await storage.credentials.list(session.user),
255
271
  });
256
272
  });
273
+ /** The parameter of the authentication page a link's token is in */
274
+ const linked = "_link";
275
+ const link = Route.post(paths.link)
276
+ .fields({ link: Field.hidden() })
277
+ .use(guard("link"), async (c) => {
278
+ const input = await Issue.data(c);
279
+ if (!input || input.issues)
280
+ throw new Issue("link request");
281
+ // once, and only at the origin it was made for
282
+ const user = await storage.links.take(input.data.link, options.origin);
283
+ if (!user)
284
+ throw new Issue("link");
285
+ await enter(c, user);
286
+ });
257
287
  const routes = [
258
288
  register,
259
289
  login,
260
290
  logout,
261
291
  add,
292
+ link,
262
293
  registration,
263
294
  assertion,
264
295
  adding,
@@ -266,6 +297,22 @@ export function configure(options, storage, state) {
266
297
  ];
267
298
  return {
268
299
  routes,
300
+ /** Make a link that signs a user in once, see `Auth.link`. */
301
+ async link(user, { origin = options.origin, minutes = 10, } = {}) {
302
+ const target = new URL(page, origin);
303
+ if (target.protocol !== "https:" || target.origin !== origin)
304
+ throw new TypeError("A link's origin must be an HTTPS origin");
305
+ if (!(minutes > 0 && minutes <= 60))
306
+ throw new TypeError("A link lasts at most 60 minutes");
307
+ const token = Token.random();
308
+ await storage.links.set(token, {
309
+ user,
310
+ origin,
311
+ expiration: Date.now() + minutes * Time.minute,
312
+ });
313
+ target.searchParams.set(linked, token);
314
+ return target.href;
315
+ },
269
316
  /** Create forms in the handler before returning JSX, so ovr can set the binding cookie. */
270
317
  forms(c, props = {}) {
271
318
  const passkey = new Passkey(c, state(c));
@@ -297,7 +344,9 @@ export function configure(options, storage, state) {
297
344
  ? "Registration could not be completed. If you already registered, sign in; otherwise try again."
298
345
  : method === "add"
299
346
  ? "The passkey could not be added. Try again."
300
- : "Authentication failed. Try again."
347
+ : method === "link"
348
+ ? "This link has expired or was already used."
349
+ : "Authentication failed. Try again."
301
350
  : undefined),
302
351
  });
303
352
  // another passkey for the account signed in, such as on a new device
@@ -309,6 +358,21 @@ export function configure(options, storage, state) {
309
358
  Register.Issue = error("register", Register.Issue);
310
359
  Login.Issue = error("login", Login.Issue);
311
360
  Add.Issue = error("add", Add.Issue);
361
+ // a link's token, from the address the link opened
362
+ const token = c.url.searchParams.get(linked);
363
+ const Link = Object.assign((props) => (token || failure === "link") &&
364
+ jsx(link.Form, {
365
+ ...props,
366
+ children: [
367
+ token && [
368
+ jsx("input", { type: "hidden", name: "link", value: token }),
369
+ props.children ?? jsx("button", { children: "Sign in" }),
370
+ ],
371
+ Link.Issue({}),
372
+ ],
373
+ }), {
374
+ Issue: error("link", (props) => jsx("p", { role: "status", "aria-live": "polite", ...props })),
375
+ });
312
376
  return {
313
377
  Register: Object.assign(Register, {
314
378
  Field: fields.Field,
@@ -316,6 +380,7 @@ export function configure(options, storage, state) {
316
380
  }),
317
381
  Login,
318
382
  Add,
383
+ Link,
319
384
  Logout: (props) => jsx(logout.Form, {
320
385
  ...props,
321
386
  children: props.children ?? jsx("button", { children: "Log out" }),
@@ -36,6 +36,14 @@ export declare namespace Auth {
36
36
  Add: Route.Form<string> & {
37
37
  Issue: (props: JSX.IntrinsicElements["p"]) => JSX.Element;
38
38
  };
39
+ /**
40
+ * Signs in with a link from `auth.link`, on the authentication `page`
41
+ * the link opens. It is a button, so only a person uses the link, and
42
+ * renders nothing on a page opened without one.
43
+ */
44
+ Link: ((props: JSX.IntrinsicElements["form"]) => JSX.Element) & {
45
+ Issue: (props: JSX.IntrinsicElements["p"]) => JSX.Element;
46
+ };
39
47
  Logout: Route.Form<string>;
40
48
  }
41
49
  /** A revocable session with a fixed lifetime, from `c.session()`. */
@@ -159,6 +167,12 @@ export declare namespace Auth {
159
167
  eligible: boolean;
160
168
  /** Current backup state, which may change. */
161
169
  backedUp: boolean;
170
+ /** When it was made, in milliseconds. */
171
+ created: number;
172
+ /** Origin it was made at, the only one it signs in at. */
173
+ origin: string;
174
+ /** What the person called it when adding it, such as "Laptop". */
175
+ name: string | null;
162
176
  }
163
177
  export {};
164
178
  }
@@ -180,6 +194,9 @@ export declare class Auth<U extends Auth.Users = Auth.Users, P extends string =
180
194
  counter: Schema<number>;
181
195
  eligible: Schema<boolean>;
182
196
  backedUp: Schema<boolean>;
197
+ created: Schema<number>;
198
+ origin: Schema<string>;
199
+ name: Schema<string | null>;
183
200
  }, {}>, Table<"auth_sessions", {
184
201
  id: Schema<string>;
185
202
  user: Schema<string>;
@@ -211,6 +228,11 @@ export declare class Auth<U extends Auth.Users = Auth.Users, P extends string =
211
228
  challenge: Schema<string | null>;
212
229
  family: Schema<string>;
213
230
  expiration: Schema<number>;
231
+ }, {}>, Table<"auth_links", {
232
+ id: Schema<string>;
233
+ user: Schema<string>;
234
+ origin: Schema<string>;
235
+ expiration: Schema<number>;
214
236
  }, {}>];
215
237
  /**
216
238
  * Read an agent's authorization request on the consent page, with the form
@@ -223,6 +245,26 @@ export declare class Auth<U extends Auth.Users = Auth.Users, P extends string =
223
245
  readonly forms: (c: Auth.Context, props?: {
224
246
  nonce?: string;
225
247
  }) => Auth.Forms<Auth.Fields<U>>;
248
+ /**
249
+ * Make a link that signs a user in once, for when they have no passkey
250
+ * where they need one: at another origin that shares the users table,
251
+ * such as production after registering on `localhost`, or after losing
252
+ * their device. It opens the authentication `page`, where `<Link />` from
253
+ * `auth.forms(c)` signs them in, and they add a passkey.
254
+ *
255
+ * Anyone who has the link is the user until it is used or expires, so
256
+ * make one only for a user your code has already identified, and send it
257
+ * the way you would a password.
258
+ *
259
+ * @param user ID of the user it signs in
260
+ * @param options The origin it is opened at, this one by default, and how
261
+ * many minutes it lasts, 10 by default and at most 60
262
+ * @returns The link
263
+ */
264
+ readonly link: (user: string, options?: {
265
+ origin?: string;
266
+ minutes?: number;
267
+ }) => Promise<string>;
226
268
  /** Configure passkeys, session helpers, and automatic authentication rate limits. */
227
269
  constructor(options: Auth.Options<U, P, R, C>);
228
270
  /** Mounted by `app.use(auth)`, and lets every request read its session. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,KAAK,OAAO,IAAI,WAAW,EAAY,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,KAAK,QAAQ,EAAc,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAQ/C,yBAAiB,IAAI,CAAC;IACrB,uCAAuC;IAEvC,qEAAqE;IACrE,MAAM,MAAM,OAAO,GAAG,IAAI,CACzB,WAAW,EACX,KAAK,GAAG,QAAQ,GAAG,KAAK,GAAG,WAAW,CACtC,GAAG;QAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;IAClE;;;;OAIG;IACH,MAAM,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,CAAC,KAAK;QAC/C,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG;YAC9B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;YAC5B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CA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,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EA4D5C;IAED,2EAA2E;IAC3E,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC,CAAC,CAQ/C;IAgCD,2JAA2J;IAC3J,QAAQ,CAAC,KAAK,MACV,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,CAAC,QACzC,MAAM;;;;OAGX;IAEF,kFAAkF;IAClF,QAAQ,CAAC,MAAM,MAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,CAAC,mBAEhE;IAEF;;;;;;;;OAQG;IACH,QAAQ,CAAC,UAAU,MACf,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,CAAC,UACvC,MAAM,mBAKb;CACF"}
@@ -24,6 +24,7 @@ export class Auth {
24
24
  Storage.challenges,
25
25
  Limiter.table,
26
26
  Storage.tokens,
27
+ Storage.links,
27
28
  ];
28
29
  #options;
29
30
  #states = new WeakMap();
@@ -42,6 +43,23 @@ export class Auth {
42
43
  [agents];
43
44
  /** Prepare request-scoped UI in the handler before returning JSX. */
44
45
  forms;
46
+ /**
47
+ * Make a link that signs a user in once, for when they have no passkey
48
+ * where they need one: at another origin that shares the users table,
49
+ * such as production after registering on `localhost`, or after losing
50
+ * their device. It opens the authentication `page`, where `<Link />` from
51
+ * `auth.forms(c)` signs them in, and they add a passkey.
52
+ *
53
+ * Anyone who has the link is the user until it is used or expires, so
54
+ * make one only for a user your code has already identified, and send it
55
+ * the way you would a password.
56
+ *
57
+ * @param user ID of the user it signs in
58
+ * @param options The origin it is opened at, this one by default, and how
59
+ * many minutes it lasts, 10 by default and at most 60
60
+ * @returns The link
61
+ */
62
+ link;
45
63
  /** Configure passkeys, session helpers, and automatic authentication rate limits. */
46
64
  constructor(options) {
47
65
  const origin = new URL(options.origin);
@@ -77,6 +95,7 @@ export class Auth {
77
95
  const signin = oauth(options, storage, (c) => this.#state(c), resources);
78
96
  this.#routes = service.routes;
79
97
  this.forms = service.forms;
98
+ this.link = service.link;
80
99
  this.consent = signin.consent;
81
100
  this[agents] = {
82
101
  origin: options.origin,
@@ -85,6 +85,9 @@ export declare class Passkey {
85
85
  counter: number;
86
86
  eligible: boolean;
87
87
  backedUp: boolean;
88
+ created: number;
89
+ origin: string;
90
+ name: string | null;
88
91
  }>;
89
92
  /**
90
93
  * Verify login and atomically update the credential.
@@ -102,6 +105,9 @@ export declare class Passkey {
102
105
  user: string;
103
106
  publicKey: string;
104
107
  eligible: boolean;
108
+ created: number;
109
+ origin: string;
110
+ name: string | null;
105
111
  }>;
106
112
  }
107
113
  //# sourceMappingURL=passkey.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"passkey.d.ts","sourceRoot":"","sources":["../../src/auth/passkey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAO1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,yBAAiB,OAAO,CAAC;IACxB;;;;OAIG;IACH,KAAY,SAAS,CAAC,OAAO,SAAS,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG;QACrE,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,OAAO,C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E,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;KACzB,CACH,CAAC;CACF;AAED,gEAAgE;AAChE,qBAAa,OAAO;;IAGnB,iFAAiF;IACjF,MAAM,CAAC,QAAQ,CAAC,KAAK;QACpB,UAAU;QACV,QAAQ;MACP;IAqCF,6CAA6C;IAC7C,YAAY,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAGvC;IAED;;;;OAIG;IACH,IAAI,CAAC,OAAO,SAAS,MAAM,EAC1B,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAC5B,MAAM,EAAE,UAAU,GAAG,OAAO,EAC5B,OAAO,EAAE,OAAO,CAAC,OAAO,8BA4DxB;IAED,0FAA0F;IAC1F,MAAM,CAAC,QAAQ,CAAC,MAAM,gEAoBnB;IAOH,2DAA2D;IAC3D,OAAa,KAAK,CACjB,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC,EACrD,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,OAAO,CAAC,QAAQ,iBA8F1B;IAqID,oFAAoF;IACpF,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,mBAa3B;IAED,8DAA8D;IACxD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;;;;;;;;;cAkCd,MAAM,GAAG,IAAI;OAE5B;IAED;;;;;;;;OAQG;IACG,KAAK,CACV,WAAW,EAAE,OAAO,CAAC,WAAW,EAChC,MAAM,CAAC,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM;;;;;;;;;;OAmDb;CACD"}
@@ -350,6 +350,10 @@ export class Passkey {
350
350
  counter: data.counter,
351
351
  eligible: Boolean(data.flags & 8),
352
352
  backedUp: Boolean(data.flags & 16),
353
+ created: Date.now(),
354
+ origin: this.#auth.options.origin,
355
+ // what a person calls one they add
356
+ name: null,
353
357
  };
354
358
  }
355
359
  /**
@@ -76,6 +76,16 @@ export declare class Storage {
76
76
  counter: Schema<number>;
77
77
  eligible: Schema<boolean>;
78
78
  backedUp: Schema<boolean>;
79
+ created: Schema<number>;
80
+ origin: Schema<string>;
81
+ name: Schema<string | null>;
82
+ }, {}>;
83
+ /** One-time sign-in links, by the hash of their token. */
84
+ static readonly links: Table<"auth_links", {
85
+ id: Schema<string>;
86
+ user: Schema<string>;
87
+ origin: Schema<string>;
88
+ expiration: Schema<number>;
79
89
  }, {}>;
80
90
  /** Revocable sessions. */
81
91
  static readonly sessions: Table<"auth_sessions", {
@@ -117,6 +127,9 @@ export declare class Storage {
117
127
  counter: Schema<number>;
118
128
  eligible: Schema<boolean>;
119
129
  backedUp: Schema<boolean>;
130
+ created: Schema<number>;
131
+ origin: Schema<string>;
132
+ name: Schema<string | null>;
120
133
  }, {}>, Table<"auth_sessions", {
121
134
  id: Schema<string>;
122
135
  user: Schema<string>;
@@ -133,6 +146,11 @@ export declare class Storage {
133
146
  challenge: Schema<string | null>;
134
147
  family: Schema<string>;
135
148
  expiration: Schema<number>;
149
+ }, {}>, Table<"auth_links", {
150
+ id: Schema<string>;
151
+ user: Schema<string>;
152
+ origin: Schema<string>;
153
+ expiration: Schema<number>;
136
154
  }, {}>];
137
155
  /**
138
156
  * @param db Database containing the authentication tables
@@ -181,6 +199,26 @@ export declare class Storage {
181
199
  readonly challenges: Storage.Challenges;
182
200
  readonly sessions: Storage.Sessions;
183
201
  readonly credentials: Storage.Credentials;
202
+ readonly links: {
203
+ /**
204
+ * @param token Link's token, stored by its hash
205
+ * @param link Who it signs in, where, and until when
206
+ */
207
+ set: (token: string, link: {
208
+ user: string;
209
+ origin: string;
210
+ expiration: number;
211
+ }) => Promise<void>;
212
+ /**
213
+ * Uses a link once: concurrent calls have one winner.
214
+ *
215
+ * @param token Link's token
216
+ * @param origin Origin it is opened at
217
+ * @returns The user it signs in, nothing when it is used, expired, or
218
+ * for another origin
219
+ */
220
+ take: (token: string, origin: string) => Promise<string | undefined>;
221
+ };
184
222
  /**
185
223
  * Create the account and its first credential in one transaction.
186
224
  *
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/auth/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,QAAQ,EAIb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC;;;;GAIG;AACH,KAAK,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhC,yBAAiB,OAAO,CAAC;IACxB,mDAAmD;IACnD,UAAiB,SAAS;QACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC;QACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QACvB,4FAA4F;QAC5F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;KACzB;IAED,qDAAqD;IACrD,UAAiB,UAAU;QAC1B,uEAAuE;QACvE,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC;QAC9D,+EAA+E;QAC/E,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;KACvD;IAED,mEAAmE;IACnE,UAAiB,O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C,KAAK,KACd,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;QAiExD;;;;;;WAMG;QACH,MAAM,SAAe,MAAM,UAAU,MAAM;QAS3C;;;WAGG;QACH,GAAG,UAAgB,MAAM;MAOxB;IAyEF,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAsCrC;IAEF,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAuBjC;IAEF,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,CAgCvC;IAEF,QAAQ,CAAC,KAAK;QACb;;;WAGG;QACH,GAAG,UACK,MAAM,QACP;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAA;SAAE;QAM3D;;;;;;;WAOG;QACH,IAAI,UAAgB,MAAM,UAAU,MAAM;MAWzC;IAEF;;;;;OAKG;IACH,QAAQ,CACP,MAAM,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,EAC/D,UAAU,EAAE,IAAI,CAAC,UAAU,iBAM3B;CACD"}
@@ -15,6 +15,17 @@ export class Storage {
15
15
  counter: Schema.number().int(),
16
16
  eligible: Schema.boolean(),
17
17
  backedUp: Schema.boolean(),
18
+ // what tells an account's passkeys apart
19
+ created: Schema.number().int(),
20
+ origin: Schema.string(),
21
+ name: Schema.string().nullable(),
22
+ });
23
+ /** One-time sign-in links, by the hash of their token. */
24
+ static links = new Table("auth_links", {
25
+ id: Schema.string(),
26
+ user: Schema.string(),
27
+ origin: Schema.string(),
28
+ expiration: Schema.number().int(),
18
29
  });
19
30
  /** Revocable sessions. */
20
31
  static sessions = new Table("auth_sessions", {
@@ -64,7 +75,10 @@ export class Storage {
64
75
  "publicKey" text NOT NULL,
65
76
  counter bigint NOT NULL,
66
77
  eligible boolean NOT NULL,
67
- "backedUp" boolean NOT NULL
78
+ "backedUp" boolean NOT NULL,
79
+ created bigint NOT NULL,
80
+ origin text NOT NULL,
81
+ name text
68
82
  );
69
83
  CREATE INDEX auth_credentials_user ON auth_credentials ("user");
70
84
 
@@ -105,7 +119,16 @@ CREATE TABLE auth_tokens (
105
119
  );
106
120
  CREATE INDEX auth_tokens_family ON auth_tokens (family);
107
121
  CREATE INDEX auth_tokens_user ON auth_tokens ("user");
108
- CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
122
+ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);
123
+
124
+ CREATE TABLE auth_links (
125
+ id text PRIMARY KEY,
126
+ "user" text NOT NULL,
127
+ origin text NOT NULL,
128
+ expiration bigint NOT NULL
129
+ );
130
+ CREATE INDEX auth_links_user ON auth_links ("user");
131
+ CREATE INDEX auth_links_expiration ON auth_links (expiration);`,
109
132
  },
110
133
  ];
111
134
  /** Tables whose rows belong to a user, and must reference the users table. */
@@ -113,6 +136,7 @@ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
113
136
  Storage.credentials,
114
137
  Storage.sessions,
115
138
  Storage.tokens,
139
+ Storage.links,
116
140
  ];
117
141
  static {
118
142
  for (const table of [...Storage.owners, Storage.challenges])
@@ -151,7 +175,11 @@ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
151
175
  if (Math.abs(now - this.#pruned) < Time.minute)
152
176
  return;
153
177
  this.#pruned = now;
154
- const tables = [Storage.challenges, Storage.sessions];
178
+ const tables = [
179
+ Storage.challenges,
180
+ Storage.sessions,
181
+ Storage.links,
182
+ ];
155
183
  if (this.#oauth)
156
184
  tables.push(Storage.tokens);
157
185
  for (const table of tables)
@@ -395,6 +423,35 @@ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
395
423
  return rows.length === 1;
396
424
  },
397
425
  };
426
+ links = {
427
+ /**
428
+ * @param token Link's token, stored by its hash
429
+ * @param link Who it signs in, where, and until when
430
+ */
431
+ set: async (token, link) => {
432
+ await this.#prune();
433
+ await this.#db
434
+ .sql `INSERT INTO ${Storage.links} ${this.#db.sql.values(Storage.links, { ...link, id: await Storage.hash(token) })}`;
435
+ },
436
+ /**
437
+ * Uses a link once: concurrent calls have one winner.
438
+ *
439
+ * @param token Link's token
440
+ * @param origin Origin it is opened at
441
+ * @returns The user it signs in, nothing when it is used, expired, or
442
+ * for another origin
443
+ */
444
+ take: async (token, origin) => {
445
+ const { columns } = Storage.links;
446
+ const [row] = await this.#db.sql `
447
+ DELETE FROM ${Storage.links}
448
+ WHERE ${columns.id} = ${await Storage.hash(token)}
449
+ AND ${columns.origin} = ${origin} AND ${columns.expiration} > ${Date.now()}
450
+ RETURNING *
451
+ `.parse(Storage.links);
452
+ return row?.user;
453
+ },
454
+ };
398
455
  /**
399
456
  * Create the account and its first credential in one transaction.
400
457
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ovr",
3
3
  "description": "Web apps anyone can use. Each route serves people a page and agents Markdown and MCP tools, with forms, Postgres, and passkey sign-in built in.",
4
- "version": "7.0.0-next.15",
4
+ "version": "7.0.0-next.16",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -11,6 +11,7 @@ import { Issue } from "./issue.js";
11
11
  import { Passkey } from "./passkey.js";
12
12
  import type { State } from "./state.js";
13
13
  import type { Storage } from "./storage.js";
14
+ import { Token } from "./token.js";
14
15
 
15
16
  /**
16
17
  * Construct startup-complete handlers and request-scoped UI components.
@@ -53,6 +54,7 @@ export function configure<U extends Auth.Users>(
53
54
  login: "/auth/login",
54
55
  logout: "/auth/logout",
55
56
  passkey: "/auth/passkey",
57
+ link: "/auth/link",
56
58
  options: "/_passkey/options",
57
59
  } as const;
58
60
  const page = options.page ?? "/login";
@@ -119,10 +121,11 @@ export function configure<U extends Auth.Users>(
119
121
 
120
122
  const admit = async (
121
123
  c: Limiter.Context & Pick<Context, "text" | "redirect" | "url">,
122
- method: "register" | "login" | "add",
124
+ method: "register" | "login" | "add" | "link",
123
125
  prompt: boolean,
124
126
  ) => {
125
- const admission = await limits[method].check(
127
+ // a link signs in, so it shares a login's limit
128
+ const admission = await limits[method === "link" ? "login" : method].check(
126
129
  c,
127
130
  prompt ? "options" : "verify",
128
131
  );
@@ -148,7 +151,10 @@ export function configure<U extends Auth.Users>(
148
151
  c.redirect(state(c).resume(redirect), 303);
149
152
  };
150
153
  const guard =
151
- (method: "register" | "login" | "logout" | "add", prompt = false) =>
154
+ (
155
+ method: "register" | "login" | "logout" | "add" | "link",
156
+ prompt = false,
157
+ ) =>
152
158
  async (
153
159
  c: Limiter.Context & Pick<Context, "text" | "redirect" | "url">,
154
160
  next: Middleware.Next,
@@ -260,17 +266,29 @@ export function configure<U extends Auth.Users>(
260
266
  action: paths.login,
261
267
  });
262
268
  });
269
+ /** What a person calls a passkey they add, such as "Laptop" */
270
+ const naming = {
271
+ name: Field.text()
272
+ .max(64)
273
+ .optional()
274
+ .label("Name")
275
+ .hint("Such as the device it is on"),
276
+ };
263
277
  const add = Route.post(paths.passkey)
264
- .fields(Passkey.shape)
278
+ .fields({ ...naming, ...Passkey.shape })
265
279
  .use(guard("add"), async (c) => {
266
- if (!(await Issue.data(c))) throw new Issue("passkey request");
280
+ const input = await Issue.data(c);
281
+ if (!input || input.issues) throw new Issue("passkey request");
267
282
  const session = await state(c).session();
268
283
  if (!session) throw new Issue("session");
269
284
  const credential = await new Passkey(c, state(c)).register();
270
285
  // the account that started the ceremony is still the one signed in
271
286
  if (credential.user !== session.user) throw new Issue("user");
272
287
  await storage
273
- .register(() => {}, credential)
288
+ .register(() => {}, {
289
+ ...credential,
290
+ name: input.data.name?.trim() || null,
291
+ })
274
292
  .catch((error: unknown) => {
275
293
  // a passkey that is already an account's
276
294
  if (Database.unique(error)) throw new Issue("passkey");
@@ -279,7 +297,8 @@ export function configure<U extends Auth.Users>(
279
297
  c.redirect(returning(c), 303);
280
298
  });
281
299
  const adding = Route.post(`${paths.options}/add`)
282
- .fields({ bootstrap: Field.hidden() })
300
+ // the form's own field is sent with it, and saved when it submits
301
+ .fields({ ...naming, bootstrap: Field.hidden() })
283
302
  .use(guard("add", true), async (c) => {
284
303
  const input = await Issue.data(c);
285
304
  if (!input || input.issues) throw new Issue("passkey request");
@@ -295,11 +314,24 @@ export function configure<U extends Auth.Users>(
295
314
  exclude: await storage.credentials.list(session.user),
296
315
  });
297
316
  });
317
+ /** The parameter of the authentication page a link's token is in */
318
+ const linked = "_link";
319
+ const link = Route.post(paths.link)
320
+ .fields({ link: Field.hidden() })
321
+ .use(guard("link"), async (c) => {
322
+ const input = await Issue.data(c);
323
+ if (!input || input.issues) throw new Issue("link request");
324
+ // once, and only at the origin it was made for
325
+ const user = await storage.links.take(input.data.link, options.origin);
326
+ if (!user) throw new Issue("link");
327
+ await enter(c, user);
328
+ });
298
329
  const routes = [
299
330
  register,
300
331
  login,
301
332
  logout,
302
333
  add,
334
+ link,
303
335
  registration,
304
336
  assertion,
305
337
  adding,
@@ -307,6 +339,29 @@ export function configure<U extends Auth.Users>(
307
339
  ];
308
340
  return {
309
341
  routes,
342
+ /** Make a link that signs a user in once, see `Auth.link`. */
343
+ async link(
344
+ user: string,
345
+ {
346
+ origin = options.origin,
347
+ minutes = 10,
348
+ }: { origin?: string; minutes?: number } = {},
349
+ ) {
350
+ const target = new URL(page, origin);
351
+ if (target.protocol !== "https:" || target.origin !== origin)
352
+ throw new TypeError("A link's origin must be an HTTPS origin");
353
+ if (!(minutes > 0 && minutes <= 60))
354
+ throw new TypeError("A link lasts at most 60 minutes");
355
+
356
+ const token = Token.random();
357
+ await storage.links.set(token, {
358
+ user,
359
+ origin,
360
+ expiration: Date.now() + minutes * Time.minute,
361
+ });
362
+ target.searchParams.set(linked, token);
363
+ return target.href;
364
+ },
310
365
  /** Create forms in the handler before returning JSX, so ovr can set the binding cookie. */
311
366
  forms(
312
367
  c: Auth.Context,
@@ -345,7 +400,9 @@ export function configure<U extends Auth.Users>(
345
400
  ? "Registration could not be completed. If you already registered, sign in; otherwise try again."
346
401
  : method === "add"
347
402
  ? "The passkey could not be added. Try again."
348
- : "Authentication failed. Try again."
403
+ : method === "link"
404
+ ? "This link has expired or was already used."
405
+ : "Authentication failed. Try again."
349
406
  : undefined),
350
407
  });
351
408
  // another passkey for the account signed in, such as on a new device
@@ -357,6 +414,27 @@ export function configure<U extends Auth.Users>(
357
414
  Register.Issue = error("register", Register.Issue);
358
415
  Login.Issue = error("login", Login.Issue);
359
416
  Add.Issue = error("add", Add.Issue);
417
+ // a link's token, from the address the link opened
418
+ const token = c.url.searchParams.get(linked);
419
+ const Link = Object.assign(
420
+ (props: Parameters<typeof link.Form>[0]) =>
421
+ (token || failure === "link") &&
422
+ jsx(link.Form, {
423
+ ...props,
424
+ children: [
425
+ token && [
426
+ jsx("input", { type: "hidden", name: "link", value: token }),
427
+ props.children ?? jsx("button", { children: "Sign in" }),
428
+ ],
429
+ Link.Issue({}),
430
+ ],
431
+ }),
432
+ {
433
+ Issue: error("link", (props: Parameters<typeof Add.Issue>[0]) =>
434
+ jsx("p", { role: "status", "aria-live": "polite", ...props }),
435
+ ),
436
+ },
437
+ );
360
438
  return {
361
439
  Register: Object.assign(Register, {
362
440
  Field: fields.Field,
@@ -364,6 +442,7 @@ export function configure<U extends Auth.Users>(
364
442
  }),
365
443
  Login,
366
444
  Add,
445
+ Link,
367
446
  Logout: (props: Parameters<typeof logout.Form>[0]) =>
368
447
  jsx(logout.Form, {
369
448
  ...props,
package/src/auth/index.ts CHANGED
@@ -44,6 +44,14 @@ export namespace Auth {
44
44
  Add: Route.Form<string> & {
45
45
  Issue: (props: JSX.IntrinsicElements["p"]) => JSX.Element;
46
46
  };
47
+ /**
48
+ * Signs in with a link from `auth.link`, on the authentication `page`
49
+ * the link opens. It is a button, so only a person uses the link, and
50
+ * renders nothing on a page opened without one.
51
+ */
52
+ Link: ((props: JSX.IntrinsicElements["form"]) => JSX.Element) & {
53
+ Issue: (props: JSX.IntrinsicElements["p"]) => JSX.Element;
54
+ };
47
55
  Logout: Route.Form<string>;
48
56
  }
49
57
 
@@ -210,6 +218,12 @@ export namespace Auth {
210
218
  eligible: boolean;
211
219
  /** Current backup state, which may change. */
212
220
  backedUp: boolean;
221
+ /** When it was made, in milliseconds. */
222
+ created: number;
223
+ /** Origin it was made at, the only one it signs in at. */
224
+ origin: string;
225
+ /** What the person called it when adding it, such as "Laptop". */
226
+ name: string | null;
213
227
  }
214
228
  }
215
229
 
@@ -234,6 +248,7 @@ export class Auth<
234
248
  Storage.challenges,
235
249
  Limiter.table,
236
250
  Storage.tokens,
251
+ Storage.links,
237
252
  ] as const;
238
253
 
239
254
  readonly #options: State.Options;
@@ -258,6 +273,27 @@ export class Auth<
258
273
  props?: { nonce?: string },
259
274
  ) => Auth.Forms<Auth.Fields<U>>;
260
275
 
276
+ /**
277
+ * Make a link that signs a user in once, for when they have no passkey
278
+ * where they need one: at another origin that shares the users table,
279
+ * such as production after registering on `localhost`, or after losing
280
+ * their device. It opens the authentication `page`, where `<Link />` from
281
+ * `auth.forms(c)` signs them in, and they add a passkey.
282
+ *
283
+ * Anyone who has the link is the user until it is used or expires, so
284
+ * make one only for a user your code has already identified, and send it
285
+ * the way you would a password.
286
+ *
287
+ * @param user ID of the user it signs in
288
+ * @param options The origin it is opened at, this one by default, and how
289
+ * many minutes it lasts, 10 by default and at most 60
290
+ * @returns The link
291
+ */
292
+ readonly link: (
293
+ user: string,
294
+ options?: { origin?: string; minutes?: number },
295
+ ) => Promise<string>;
296
+
261
297
  /** Configure passkeys, session helpers, and automatic authentication rate limits. */
262
298
  constructor(options: Auth.Options<U, P, R, C>) {
263
299
  const origin = new URL(options.origin);
@@ -298,6 +334,7 @@ export class Auth<
298
334
  const signin = oauth(options, storage, (c) => this.#state(c), resources);
299
335
  this.#routes = service.routes;
300
336
  this.forms = service.forms;
337
+ this.link = service.link;
301
338
  this.consent = signin.consent;
302
339
  this[agents] = {
303
340
  origin: options.origin,
@@ -500,6 +500,10 @@ export class Passkey {
500
500
  counter: data.counter,
501
501
  eligible: Boolean(data.flags & 8),
502
502
  backedUp: Boolean(data.flags & 16),
503
+ created: Date.now(),
504
+ origin: this.#auth.options.origin,
505
+ // what a person calls one they add
506
+ name: null as string | null,
503
507
  };
504
508
  }
505
509
 
@@ -95,6 +95,18 @@ export class Storage {
95
95
  counter: Schema.number().int(),
96
96
  eligible: Schema.boolean(),
97
97
  backedUp: Schema.boolean(),
98
+ // what tells an account's passkeys apart
99
+ created: Schema.number().int(),
100
+ origin: Schema.string(),
101
+ name: Schema.string().nullable(),
102
+ });
103
+
104
+ /** One-time sign-in links, by the hash of their token. */
105
+ static readonly links = new Table("auth_links", {
106
+ id: Schema.string(),
107
+ user: Schema.string(),
108
+ origin: Schema.string(),
109
+ expiration: Schema.number().int(),
98
110
  });
99
111
 
100
112
  /** Revocable sessions. */
@@ -148,7 +160,10 @@ export class Storage {
148
160
  "publicKey" text NOT NULL,
149
161
  counter bigint NOT NULL,
150
162
  eligible boolean NOT NULL,
151
- "backedUp" boolean NOT NULL
163
+ "backedUp" boolean NOT NULL,
164
+ created bigint NOT NULL,
165
+ origin text NOT NULL,
166
+ name text
152
167
  );
153
168
  CREATE INDEX auth_credentials_user ON auth_credentials ("user");
154
169
 
@@ -189,7 +204,16 @@ CREATE TABLE auth_tokens (
189
204
  );
190
205
  CREATE INDEX auth_tokens_family ON auth_tokens (family);
191
206
  CREATE INDEX auth_tokens_user ON auth_tokens ("user");
192
- CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
207
+ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);
208
+
209
+ CREATE TABLE auth_links (
210
+ id text PRIMARY KEY,
211
+ "user" text NOT NULL,
212
+ origin text NOT NULL,
213
+ expiration bigint NOT NULL
214
+ );
215
+ CREATE INDEX auth_links_user ON auth_links ("user");
216
+ CREATE INDEX auth_links_expiration ON auth_links (expiration);`,
193
217
  },
194
218
  ] as const;
195
219
 
@@ -198,6 +222,7 @@ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
198
222
  Storage.credentials,
199
223
  Storage.sessions,
200
224
  Storage.tokens,
225
+ Storage.links,
201
226
  ] as const;
202
227
 
203
228
  static {
@@ -245,7 +270,11 @@ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
245
270
  if (Math.abs(now - this.#pruned) < Time.minute) return;
246
271
 
247
272
  this.#pruned = now;
248
- const tables: Table<string, any>[] = [Storage.challenges, Storage.sessions];
273
+ const tables: Table<string, any>[] = [
274
+ Storage.challenges,
275
+ Storage.sessions,
276
+ Storage.links,
277
+ ];
249
278
  if (this.#oauth) tables.push(Storage.tokens);
250
279
  for (const table of tables)
251
280
  await this.#db.sql`DELETE FROM ${table} WHERE expiration <= ${now}`;
@@ -554,6 +583,40 @@ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
554
583
  },
555
584
  };
556
585
 
586
+ readonly links = {
587
+ /**
588
+ * @param token Link's token, stored by its hash
589
+ * @param link Who it signs in, where, and until when
590
+ */
591
+ set: async (
592
+ token: string,
593
+ link: { user: string; origin: string; expiration: number },
594
+ ) => {
595
+ await this.#prune();
596
+ await this.#db
597
+ .sql`INSERT INTO ${Storage.links} ${this.#db.sql.values(Storage.links, { ...link, id: await Storage.hash(token) })}`;
598
+ },
599
+ /**
600
+ * Uses a link once: concurrent calls have one winner.
601
+ *
602
+ * @param token Link's token
603
+ * @param origin Origin it is opened at
604
+ * @returns The user it signs in, nothing when it is used, expired, or
605
+ * for another origin
606
+ */
607
+ take: async (token: string, origin: string) => {
608
+ const { columns } = Storage.links;
609
+ const [row] = await this.#db.sql`
610
+ DELETE FROM ${Storage.links}
611
+ WHERE ${columns.id} = ${await Storage.hash(token)}
612
+ AND ${columns.origin} = ${origin} AND ${columns.expiration} > ${Date.now()}
613
+ RETURNING *
614
+ `.parse(Storage.links);
615
+
616
+ return row?.user;
617
+ },
618
+ };
619
+
557
620
  /**
558
621
  * Create the account and its first credential in one transaction.
559
622
  *