ovr 7.0.0-next.20 → 7.0.0-next.22

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,17 @@
1
1
  # ovr
2
2
 
3
+ ## 7.0.0-next.22
4
+
5
+ ### Patch Changes
6
+
7
+ - aec8805: When adding a passkey asks for a recent sign-in, the `Add` form confirms the person with a passkey they already have, and they press the button once more to add the new one. They no longer sign out and in again.
8
+
9
+ ## 7.0.0-next.21
10
+
11
+ ### Patch Changes
12
+
13
+ - cdfc7de: Adding a passkey asks for a sign-in within the last ten minutes, in that browser. A passkey outlasts the session that adds it, so a session taken over later cannot make itself a permanent way in. The form says to sign in again.
14
+
3
15
  ## 7.0.0-next.20
4
16
 
5
17
  ### Patch Changes
@@ -1,3 +1,3 @@
1
- export declare const source = "export function listen(e,t,n,r){let i=document.getElementById(e),a=i?.closest(`form`),o=i?.previousElementSibling,s=a?.querySelector(`[data-passkey-error]:not([data-passkey-fallback])`)??o;if(!(a instanceof HTMLFormElement)||!(s instanceof HTMLElement))return;s!==o&&o instanceof HTMLElement&&(o.hidden=!0);let c=e=>{let t=a.elements.namedItem(e);if(t instanceof HTMLInputElement)return t;let n=document.createElement(`input`);return n.type=`hidden`,n.name=e,a.append(n),n},l=c(`credential`),u=c(`ceremony`),d=!1,f=!1,p=!1,m,h=0,g,_=()=>`Too many requests. Try again in ${Math.ceil((h-Date.now())/1e3)} seconds.`,v=()=>{clearTimeout(g),g=void 0,d=f=p=!1,m=void 0,l.value=u.value=``,a.removeAttribute(`aria-busy`)},y=(e,t)=>{e instanceof HTMLElement&&`setCustomValidity`in e&&typeof e.setCustomValidity==`function`&&e.setCustomValidity(t)},b=e=>y(e.target,``);return a.addEventListener(`input`,b),a.addEventListener(`change`,b),a.addEventListener(`submit`,async e=>{if(!e.submitter?.hasAttribute(`formaction`)){if(f){p?m=e:e.preventDefault();return}if(e.preventDefault(),!d){if(h>Date.now()){s.textContent=_();return}d=!0,s.textContent=``,a.setAttribute(`aria-busy`,`true`);try{if(!window.PublicKeyCredential?.parseCreationOptionsFromJSON||!PublicKeyCredential.parseRequestOptionsFromJSON||!navigator.credentials)throw Error(`Passkeys are unavailable in this browser.`);let i=new FormData(a);i.delete(`credential`),i.delete(`ceremony`),i.set(`bootstrap`,t);let o=await fetch(n,{method:`POST`,body:i,credentials:`same-origin`,cache:`no-store`});if(o.status===429){let e=Date.now(),t=o.headers.get(`retry-after`)??`60`,n=/^\\d+$/.test(t)?e+Number(t)*1e3:Date.parse(t);throw h=Number.isNaN(n)?e+6e4:Math.min(e+36e5,Math.max(e+1e3,n)),Error(_())}if(o.status===422){let e=await o.json();if(e.fields&&typeof e.fields==`object`)for(let[t,n]of Object.entries(e.fields))typeof n==`string`&&y(a.elements.namedItem(t),n);throw a.reportValidity(),Error(`Check your registration details and try again.`)}if(o.status===410)throw Error(`This page has expired. Reload and try again.`);if(!o.ok)throw Error(`Could not start the passkey request. Try again.`);let c=await o.json();u.value=c.ceremony;let d=await(r===`register`?navigator.credentials.create({publicKey:PublicKeyCredential.parseCreationOptionsFromJSON(c.options)}):navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(c.options)}));if(!(d instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);l.value=JSON.stringify(d),f=!0,p=!0,m=void 0,HTMLFormElement.prototype.requestSubmit.call(a,e.submitter??void 0),p=!1,f=!!(m&&!m.defaultPrevented),f&&(g=setTimeout(()=>{v(),s.textContent=r===`register`?`If registration already completed, sign in; otherwise try again.`:`If sign-in did not finish, try again.`},12e4))}catch(e){v(),s.textContent=e instanceof DOMException&&e.name===`NotAllowedError`?`Passkey request canceled. Try again.`:e instanceof Error?e.message:`Could not complete the passkey request. Try again.`}finally{d=!1,p=!1,f||a.removeAttribute(`aria-busy`)}}}}),v}const t=new WeakMap,n=()=>document.querySelectorAll(`script[data-passkey]`),r=()=>{for(let r of n()){if(t.has(r))continue;let n=r.dataset.passkey;if(n===`register`||n===`login`){let i=listen(r.id,r.dataset.bootstrap??``,r.dataset.endpoint??``,n);i&&t.set(r,i)}}};typeof document<`u`&&(window.addEventListener(`pageshow`,e=>{if(e.persisted)for(let e of n())t.get(e)?.()}),r(),new MutationObserver(r).observe(document.documentElement,{childList:!0,subtree:!0}));";
2
- export declare const etag = "W/\"db299e39015256815ea2f2eec92a5cddf0ff95a21a5fcf8bc664bef0fd6ff6dc\"";
1
+ export declare const source = "export function listen(e,t,n,r,i){let a=document.getElementById(e),o=a?.closest(`form`),s=a?.previousElementSibling,c=o?.querySelector(`[data-passkey-error]:not([data-passkey-fallback])`)??s;if(!(o instanceof HTMLFormElement)||!(c instanceof HTMLElement))return;c!==s&&s instanceof HTMLElement&&(s.hidden=!0);let l=e=>{let t=o.elements.namedItem(e);if(t instanceof HTMLInputElement)return t;let n=document.createElement(`input`);return n.type=`hidden`,n.name=e,o.append(n),n},u=l(`credential`),d=l(`ceremony`),f=!1,p=!1,m=!1,h,g=0,_,v=()=>`Too many requests. Try again in ${Math.ceil((g-Date.now())/1e3)} seconds.`,y=()=>{clearTimeout(_),_=void 0,f=p=m=!1,h=void 0,u.value=d.value=``,o.removeAttribute(`aria-busy`)},b=(e,t)=>{e instanceof HTMLElement&&`setCustomValidity`in e&&typeof e.setCustomValidity==`function`&&e.setCustomValidity(t)},x=e=>b(e.target,``);return o.addEventListener(`input`,x),o.addEventListener(`change`,x),o.addEventListener(`submit`,async e=>{if(!e.submitter?.hasAttribute(`formaction`)){if(p){m?h=e:e.preventDefault();return}if(e.preventDefault(),!f){if(g>Date.now()){c.textContent=v();return}f=!0,c.textContent=``,o.setAttribute(`aria-busy`,`true`);try{if(!window.PublicKeyCredential?.parseCreationOptionsFromJSON||!PublicKeyCredential.parseRequestOptionsFromJSON||!navigator.credentials)throw Error(`Passkeys are unavailable in this browser.`);let a=new FormData(o);a.delete(`credential`),a.delete(`ceremony`),a.set(`bootstrap`,t);let s=await fetch(n,{method:`POST`,body:a,credentials:`same-origin`,cache:`no-store`});if(s.status===429){let e=Date.now(),t=s.headers.get(`retry-after`)??`60`,n=/^\\d+$/.test(t)?e+Number(t)*1e3:Date.parse(t);throw g=Number.isNaN(n)?e+6e4:Math.min(e+36e5,Math.max(e+1e3,n)),Error(v())}if(s.status===422){let e=await s.json();if(e.fields&&typeof e.fields==`object`)for(let[t,n]of Object.entries(e.fields))typeof n==`string`&&b(o.elements.namedItem(t),n);throw o.reportValidity(),Error(`Check your registration details and try again.`)}if(s.status===410)throw Error(`This page has expired. Reload and try again.`);if(s.status===401){if(!i)throw Error(`Sign in again, then try once more.`);let e=(e,t)=>fetch(e,{method:`POST`,body:t,credentials:`same-origin`,cache:`no-store`,redirect:`manual`}),t=new FormData;t.set(`bootstrap`,i.bootstrap);let n=await e(i.endpoint,t);if(n.status===410)throw Error(`This page has expired. Reload and try again.`);if(!n.ok)throw Error(`Sign in again, then try once more.`);let r=await n.json(),a=await navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(r.options)});if(!(a instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);let o=new FormData;throw o.set(`credential`,JSON.stringify(a)),o.set(`ceremony`,r.ceremony),(await e(i.action,o)).status===204?Error(`Confirmed. Press the button again to finish.`):Error(`Could not confirm your passkey. Try again.`)}if(!s.ok)throw Error(`Could not start the passkey request. Try again.`);let l=await s.json();d.value=l.ceremony;let f=await(r===`register`?navigator.credentials.create({publicKey:PublicKeyCredential.parseCreationOptionsFromJSON(l.options)}):navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(l.options)}));if(!(f instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);u.value=JSON.stringify(f),p=!0,m=!0,h=void 0,HTMLFormElement.prototype.requestSubmit.call(o,e.submitter??void 0),m=!1,p=!!(h&&!h.defaultPrevented),p&&(_=setTimeout(()=>{y(),c.textContent=r===`register`?`If registration already completed, sign in; otherwise try again.`:`If sign-in did not finish, try again.`},12e4))}catch(e){y(),c.textContent=e instanceof DOMException&&e.name===`NotAllowedError`?`Passkey request canceled. Try again.`:e instanceof Error?e.message:`Could not complete the passkey request. Try again.`}finally{f=!1,m=!1,p||o.removeAttribute(`aria-busy`)}}}}),y}const t=new WeakMap,n=()=>document.querySelectorAll(`script[data-passkey]`),r=()=>{for(let r of n()){if(t.has(r))continue;let n=r.dataset.passkey;if(n===`register`||n===`login`){let i=listen(r.id,r.dataset.bootstrap??``,r.dataset.endpoint??``,n,r.dataset.confirm?{bootstrap:r.dataset.confirm,endpoint:r.dataset.confirmEndpoint??``,action:r.dataset.confirmAction??``}:void 0);i&&t.set(r,i)}}};typeof document<`u`&&(window.addEventListener(`pageshow`,e=>{if(e.persisted)for(let e of n())t.get(e)?.()}),r(),new MutationObserver(r).observe(document.documentElement,{childList:!0,subtree:!0}));";
2
+ export declare const etag = "W/\"cd84978ac63729e95e76d936a954d6e7d110f47e0b70102a09b9e990f022a9c5\"";
3
3
  //# sourceMappingURL=client-source.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client-source.d.ts","sourceRoot":"","sources":["../../src/auth/client-source.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,MAAM,q9GAAq9G,CAAC;AACz+G,eAAO,MAAM,IAAI,2EAA2E,CAAC"}
1
+ {"version":3,"file":"client-source.d.ts","sourceRoot":"","sources":["../../src/auth/client-source.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,MAAM,k6IAAk6I,CAAC;AACt7I,eAAO,MAAM,IAAI,2EAA2E,CAAC"}
@@ -1,3 +1,3 @@
1
1
  // Generated by scripts/client.js; edit client.ts instead.
2
- export const source = "export function listen(e,t,n,r){let i=document.getElementById(e),a=i?.closest(`form`),o=i?.previousElementSibling,s=a?.querySelector(`[data-passkey-error]:not([data-passkey-fallback])`)??o;if(!(a instanceof HTMLFormElement)||!(s instanceof HTMLElement))return;s!==o&&o instanceof HTMLElement&&(o.hidden=!0);let c=e=>{let t=a.elements.namedItem(e);if(t instanceof HTMLInputElement)return t;let n=document.createElement(`input`);return n.type=`hidden`,n.name=e,a.append(n),n},l=c(`credential`),u=c(`ceremony`),d=!1,f=!1,p=!1,m,h=0,g,_=()=>`Too many requests. Try again in ${Math.ceil((h-Date.now())/1e3)} seconds.`,v=()=>{clearTimeout(g),g=void 0,d=f=p=!1,m=void 0,l.value=u.value=``,a.removeAttribute(`aria-busy`)},y=(e,t)=>{e instanceof HTMLElement&&`setCustomValidity`in e&&typeof e.setCustomValidity==`function`&&e.setCustomValidity(t)},b=e=>y(e.target,``);return a.addEventListener(`input`,b),a.addEventListener(`change`,b),a.addEventListener(`submit`,async e=>{if(!e.submitter?.hasAttribute(`formaction`)){if(f){p?m=e:e.preventDefault();return}if(e.preventDefault(),!d){if(h>Date.now()){s.textContent=_();return}d=!0,s.textContent=``,a.setAttribute(`aria-busy`,`true`);try{if(!window.PublicKeyCredential?.parseCreationOptionsFromJSON||!PublicKeyCredential.parseRequestOptionsFromJSON||!navigator.credentials)throw Error(`Passkeys are unavailable in this browser.`);let i=new FormData(a);i.delete(`credential`),i.delete(`ceremony`),i.set(`bootstrap`,t);let o=await fetch(n,{method:`POST`,body:i,credentials:`same-origin`,cache:`no-store`});if(o.status===429){let e=Date.now(),t=o.headers.get(`retry-after`)??`60`,n=/^\\d+$/.test(t)?e+Number(t)*1e3:Date.parse(t);throw h=Number.isNaN(n)?e+6e4:Math.min(e+36e5,Math.max(e+1e3,n)),Error(_())}if(o.status===422){let e=await o.json();if(e.fields&&typeof e.fields==`object`)for(let[t,n]of Object.entries(e.fields))typeof n==`string`&&y(a.elements.namedItem(t),n);throw a.reportValidity(),Error(`Check your registration details and try again.`)}if(o.status===410)throw Error(`This page has expired. Reload and try again.`);if(!o.ok)throw Error(`Could not start the passkey request. Try again.`);let c=await o.json();u.value=c.ceremony;let d=await(r===`register`?navigator.credentials.create({publicKey:PublicKeyCredential.parseCreationOptionsFromJSON(c.options)}):navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(c.options)}));if(!(d instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);l.value=JSON.stringify(d),f=!0,p=!0,m=void 0,HTMLFormElement.prototype.requestSubmit.call(a,e.submitter??void 0),p=!1,f=!!(m&&!m.defaultPrevented),f&&(g=setTimeout(()=>{v(),s.textContent=r===`register`?`If registration already completed, sign in; otherwise try again.`:`If sign-in did not finish, try again.`},12e4))}catch(e){v(),s.textContent=e instanceof DOMException&&e.name===`NotAllowedError`?`Passkey request canceled. Try again.`:e instanceof Error?e.message:`Could not complete the passkey request. Try again.`}finally{d=!1,p=!1,f||a.removeAttribute(`aria-busy`)}}}}),v}const t=new WeakMap,n=()=>document.querySelectorAll(`script[data-passkey]`),r=()=>{for(let r of n()){if(t.has(r))continue;let n=r.dataset.passkey;if(n===`register`||n===`login`){let i=listen(r.id,r.dataset.bootstrap??``,r.dataset.endpoint??``,n);i&&t.set(r,i)}}};typeof document<`u`&&(window.addEventListener(`pageshow`,e=>{if(e.persisted)for(let e of n())t.get(e)?.()}),r(),new MutationObserver(r).observe(document.documentElement,{childList:!0,subtree:!0}));";
3
- export const etag = "W/\"db299e39015256815ea2f2eec92a5cddf0ff95a21a5fcf8bc664bef0fd6ff6dc\"";
2
+ export const source = "export function listen(e,t,n,r,i){let a=document.getElementById(e),o=a?.closest(`form`),s=a?.previousElementSibling,c=o?.querySelector(`[data-passkey-error]:not([data-passkey-fallback])`)??s;if(!(o instanceof HTMLFormElement)||!(c instanceof HTMLElement))return;c!==s&&s instanceof HTMLElement&&(s.hidden=!0);let l=e=>{let t=o.elements.namedItem(e);if(t instanceof HTMLInputElement)return t;let n=document.createElement(`input`);return n.type=`hidden`,n.name=e,o.append(n),n},u=l(`credential`),d=l(`ceremony`),f=!1,p=!1,m=!1,h,g=0,_,v=()=>`Too many requests. Try again in ${Math.ceil((g-Date.now())/1e3)} seconds.`,y=()=>{clearTimeout(_),_=void 0,f=p=m=!1,h=void 0,u.value=d.value=``,o.removeAttribute(`aria-busy`)},b=(e,t)=>{e instanceof HTMLElement&&`setCustomValidity`in e&&typeof e.setCustomValidity==`function`&&e.setCustomValidity(t)},x=e=>b(e.target,``);return o.addEventListener(`input`,x),o.addEventListener(`change`,x),o.addEventListener(`submit`,async e=>{if(!e.submitter?.hasAttribute(`formaction`)){if(p){m?h=e:e.preventDefault();return}if(e.preventDefault(),!f){if(g>Date.now()){c.textContent=v();return}f=!0,c.textContent=``,o.setAttribute(`aria-busy`,`true`);try{if(!window.PublicKeyCredential?.parseCreationOptionsFromJSON||!PublicKeyCredential.parseRequestOptionsFromJSON||!navigator.credentials)throw Error(`Passkeys are unavailable in this browser.`);let a=new FormData(o);a.delete(`credential`),a.delete(`ceremony`),a.set(`bootstrap`,t);let s=await fetch(n,{method:`POST`,body:a,credentials:`same-origin`,cache:`no-store`});if(s.status===429){let e=Date.now(),t=s.headers.get(`retry-after`)??`60`,n=/^\\d+$/.test(t)?e+Number(t)*1e3:Date.parse(t);throw g=Number.isNaN(n)?e+6e4:Math.min(e+36e5,Math.max(e+1e3,n)),Error(v())}if(s.status===422){let e=await s.json();if(e.fields&&typeof e.fields==`object`)for(let[t,n]of Object.entries(e.fields))typeof n==`string`&&b(o.elements.namedItem(t),n);throw o.reportValidity(),Error(`Check your registration details and try again.`)}if(s.status===410)throw Error(`This page has expired. Reload and try again.`);if(s.status===401){if(!i)throw Error(`Sign in again, then try once more.`);let e=(e,t)=>fetch(e,{method:`POST`,body:t,credentials:`same-origin`,cache:`no-store`,redirect:`manual`}),t=new FormData;t.set(`bootstrap`,i.bootstrap);let n=await e(i.endpoint,t);if(n.status===410)throw Error(`This page has expired. Reload and try again.`);if(!n.ok)throw Error(`Sign in again, then try once more.`);let r=await n.json(),a=await navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(r.options)});if(!(a instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);let o=new FormData;throw o.set(`credential`,JSON.stringify(a)),o.set(`ceremony`,r.ceremony),(await e(i.action,o)).status===204?Error(`Confirmed. Press the button again to finish.`):Error(`Could not confirm your passkey. Try again.`)}if(!s.ok)throw Error(`Could not start the passkey request. Try again.`);let l=await s.json();d.value=l.ceremony;let f=await(r===`register`?navigator.credentials.create({publicKey:PublicKeyCredential.parseCreationOptionsFromJSON(l.options)}):navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(l.options)}));if(!(f instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);u.value=JSON.stringify(f),p=!0,m=!0,h=void 0,HTMLFormElement.prototype.requestSubmit.call(o,e.submitter??void 0),m=!1,p=!!(h&&!h.defaultPrevented),p&&(_=setTimeout(()=>{y(),c.textContent=r===`register`?`If registration already completed, sign in; otherwise try again.`:`If sign-in did not finish, try again.`},12e4))}catch(e){y(),c.textContent=e instanceof DOMException&&e.name===`NotAllowedError`?`Passkey request canceled. Try again.`:e instanceof Error?e.message:`Could not complete the passkey request. Try again.`}finally{f=!1,m=!1,p||o.removeAttribute(`aria-busy`)}}}}),y}const t=new WeakMap,n=()=>document.querySelectorAll(`script[data-passkey]`),r=()=>{for(let r of n()){if(t.has(r))continue;let n=r.dataset.passkey;if(n===`register`||n===`login`){let i=listen(r.id,r.dataset.bootstrap??``,r.dataset.endpoint??``,n,r.dataset.confirm?{bootstrap:r.dataset.confirm,endpoint:r.dataset.confirmEndpoint??``,action:r.dataset.confirmAction??``}:void 0);i&&t.set(r,i)}}};typeof document<`u`&&(window.addEventListener(`pageshow`,e=>{if(e.persisted)for(let e of n())t.get(e)?.()}),r(),new MutationObserver(r).observe(document.documentElement,{childList:!0,subtree:!0}));";
3
+ export const etag = "W/\"cd84978ac63729e95e76d936a954d6e7d110f47e0b70102a09b9e990f022a9c5\"";
@@ -1,3 +1,9 @@
1
1
  /** Attach the passkey protocol to one form. Served as a normal browser module. */
2
- export declare function listen(id: string, bootstrap: string, endpoint: string, method: "register" | "login"): (() => void) | undefined;
2
+ export declare function listen(id: string, bootstrap: string, endpoint: string, method: "register" | "login",
3
+ /** Confirms the person with a passkey they have, when the form asks */
4
+ confirm?: {
5
+ bootstrap: string;
6
+ endpoint: string;
7
+ action: string;
8
+ }): (() => void) | undefined;
3
9
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/auth/client.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,wBAAgB,MAAM,CACrB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,UAAU,GAAG,OAAO,4BAyK5B"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/auth/client.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,wBAAgB,MAAM,CACrB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,UAAU,GAAG,OAAO;AAC5B,uEAAuE;AACvE,OAAO,CAAC,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,4BA4MjE"}
@@ -1,5 +1,7 @@
1
1
  /** Attach the passkey protocol to one form. Served as a normal browser module. */
2
- export function listen(id, bootstrap, endpoint, method) {
2
+ export function listen(id, bootstrap, endpoint, method,
3
+ /** Confirms the person with a passkey they have, when the form asks */
4
+ confirm) {
3
5
  const script = document.getElementById(id);
4
6
  const form = script?.closest("form");
5
7
  // the accessible error component the form renders before the script
@@ -106,6 +108,39 @@ export function listen(id, bootstrap, endpoint, method) {
106
108
  }
107
109
  if (res.status === 410)
108
110
  throw new Error("This page has expired. Reload and try again.");
111
+ // adding a passkey asks for a recent sign-in, or for a passkey the
112
+ // person already has
113
+ if (res.status === 401) {
114
+ if (!confirm)
115
+ throw new Error("Sign in again, then try once more.");
116
+ const send = (url, body) => fetch(url, {
117
+ method: "POST",
118
+ body,
119
+ credentials: "same-origin",
120
+ cache: "no-store",
121
+ redirect: "manual",
122
+ });
123
+ const ask = new FormData();
124
+ ask.set("bootstrap", confirm.bootstrap);
125
+ const asked = await send(confirm.endpoint, ask);
126
+ if (asked.status === 410)
127
+ throw new Error("This page has expired. Reload and try again.");
128
+ if (!asked.ok)
129
+ throw new Error("Sign in again, then try once more.");
130
+ const proof = await asked.json();
131
+ const mine = await navigator.credentials.get({
132
+ publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(proof.options),
133
+ });
134
+ if (!(mine instanceof PublicKeyCredential))
135
+ throw new Error("No passkey was returned. Try again.");
136
+ const answer = new FormData();
137
+ answer.set("credential", JSON.stringify(mine));
138
+ answer.set("ceremony", proof.ceremony);
139
+ if ((await send(confirm.action, answer)).status !== 204)
140
+ throw new Error("Could not confirm your passkey. Try again.");
141
+ // a browser asks for a new press before its next passkey prompt
142
+ throw new Error("Confirmed. Press the button again to finish.");
143
+ }
109
144
  if (!res.ok)
110
145
  throw new Error("Could not start the passkey request. Try again.");
111
146
  // creation options for a registration, request options for a login
@@ -166,7 +201,13 @@ const scan = () => {
166
201
  continue;
167
202
  const method = script.dataset.passkey;
168
203
  if (method === "register" || method === "login") {
169
- const reset = listen(script.id, script.dataset.bootstrap ?? "", script.dataset.endpoint ?? "", method);
204
+ const reset = listen(script.id, script.dataset.bootstrap ?? "", script.dataset.endpoint ?? "", method, script.dataset.confirm
205
+ ? {
206
+ bootstrap: script.dataset.confirm,
207
+ endpoint: script.dataset.confirmEndpoint ?? "",
208
+ action: script.dataset.confirmAction ?? "",
209
+ }
210
+ : undefined);
170
211
  if (reset)
171
212
  attached.set(script, reset);
172
213
  }
@@ -12,10 +12,15 @@ export declare function configure<U extends Auth.Users>(options: Auth.Options<U>
12
12
  routes: (Route.Used<Route.Get<"/_passkey/client.js", {}, Field.Shape>> | Route.Used<Route.Post<"/_passkey/options/add", {}, {
13
13
  name: Field.Instance<string | undefined, "input", "text", undefined, undefined, undefined>;
14
14
  bootstrap: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
15
+ }>> | Route.Used<Route.Post<"/_passkey/options/confirm", {}, {
16
+ bootstrap: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
15
17
  }>> | Route.Used<Route.Post<"/_passkey/options/login", {}, {
16
18
  bootstrap: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
17
19
  }>> | Route.Used<Route.Post<"/_passkey/options/register", {}, {
18
20
  bootstrap: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
21
+ }>> | Route.Used<Route.Post<"/auth/confirm", {}, {
22
+ credential: Field.Instance<unknown, "input", "hidden", undefined, undefined, undefined>;
23
+ ceremony: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
19
24
  }>> | Route.Used<Route.Post<"/auth/link", {}, {
20
25
  link: Field.Instance<string, "input", "hidden", undefined, undefined, undefined>;
21
26
  }>> | Route.Used<Route.Post<"/auth/login", {}, {
@@ -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;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;;;;;;;;;;;;;;;;;;;;;IAiUjC,8DAA8D;eAEvD,MAAM,eACiB;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;IAiBjD,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;EAuF9B"}
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;;;;;;;;;;;;;;;;;;;;;;;;;;IAyWjC,8DAA8D;eAEvD,MAAM,eACiB;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;IAiBjD,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;EAwF9B"}
@@ -37,6 +37,7 @@ export function configure(options, storage, state) {
37
37
  login: "/auth/login",
38
38
  logout: "/auth/logout",
39
39
  passkey: "/auth/passkey",
40
+ confirm: "/auth/confirm",
40
41
  link: "/auth/link",
41
42
  options: "/_passkey/options",
42
43
  };
@@ -258,8 +259,11 @@ export function configure(options, storage, state) {
258
259
  if (!input || input.issues)
259
260
  throw new Issue("passkey request");
260
261
  const session = await state(c).session();
261
- if (!session)
262
- return c.text("Sign in to add a passkey.", 401);
262
+ // a passkey outlasts the session that adds it, so only a person
263
+ // who has just signed in adds one, not whoever holds an old session.
264
+ // The form then confirms them with a passkey they have.
265
+ if (!session || !(await state(c).recent(10 * Time.minute)))
266
+ return c.text("Confirm your passkey to add another.", 401);
263
267
  const [[account], exclude] = await Promise.all([
264
268
  options.database
265
269
  .sql `SELECT * FROM ${users} WHERE ${users.columns.id} = ${session.user}`,
@@ -273,6 +277,40 @@ export function configure(options, storage, state) {
273
277
  exclude,
274
278
  });
275
279
  });
280
+ // Confirms the person signed in with a passkey of theirs, which starts
281
+ // their session again: what adding a passkey asks for after a while
282
+ const confirming = Route.post(`${paths.options}/confirm`)
283
+ .fields({ bootstrap: Field.hidden() })
284
+ .use(guard("login", true), async (c) => {
285
+ const input = await Issue.data(c);
286
+ if (!input || input.issues)
287
+ throw new Issue("confirm request");
288
+ const session = await state(c).session();
289
+ if (!session)
290
+ return c.text("Sign in to add a passkey.", 401);
291
+ await Passkey.issue(c, state(c), input.data.bootstrap, {
292
+ method: "login",
293
+ action: paths.confirm,
294
+ // only their own, so the picker offers no other account's
295
+ allow: await storage.credentials.list(session.user),
296
+ });
297
+ });
298
+ const confirm = Route.post(paths.confirm)
299
+ .fields(Passkey.shape)
300
+ .use(guard("login"), async (c) => {
301
+ if (!(await Issue.data(c)))
302
+ throw new Issue("confirm request");
303
+ const session = await state(c).session();
304
+ if (!session)
305
+ throw new Issue("session");
306
+ const credential = await new Passkey(c, state(c)).login(storage.credentials, undefined, session.user);
307
+ if (credential.user !== session.user)
308
+ throw new Issue("user");
309
+ // a session that starts now, in place of the old one
310
+ await state(c).login(session.user);
311
+ c.res.status = 204;
312
+ c.res.body = null;
313
+ });
276
314
  /** The parameter of the authentication page a link's token is in */
277
315
  const linked = "_link";
278
316
  const link = Route.post(paths.link)
@@ -293,6 +331,8 @@ export function configure(options, storage, state) {
293
331
  logout,
294
332
  add,
295
333
  link,
334
+ confirm,
335
+ confirming,
296
336
  registration,
297
337
  assertion,
298
338
  adding,
@@ -357,6 +397,7 @@ export function configure(options, storage, state) {
357
397
  ...props,
358
398
  endpoint: adding.url(),
359
399
  submit: "Add passkey",
400
+ confirm: { endpoint: confirming.url(), action: paths.confirm },
360
401
  });
361
402
  Register.Issue = error("register", Register.Issue);
362
403
  Login.Issue = error("login", Login.Issue);
@@ -84,7 +84,7 @@ export declare namespace Auth {
84
84
  [K in keyof U["shape"] as K extends "id" | Defaulted<U> ? never : U["shape"][K] extends Field.Any ? K : never]: Extract<U["shape"][K], Field.Any>;
85
85
  };
86
86
  /** Auth's own endpoints, which its page cannot be */
87
- type Endpoint = "/auth/register" | "/auth/login" | "/auth/logout" | "/_passkey/options/register" | "/_passkey/options/login" | "/_passkey/client.js";
87
+ type Endpoint = "/auth/register" | "/auth/login" | "/auth/logout" | "/auth/passkey" | "/auth/link" | "/auth/confirm" | "/_passkey/options/register" | "/_passkey/options/login" | "/_passkey/options/add" | "/_passkey/options/confirm" | "/_passkey/client.js";
88
88
  /**
89
89
  * A page path, a path of the app's own that is not one of Auth's endpoints.
90
90
  *
@@ -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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CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KACzB,OAAO,CAAC,MAAM,CAAC,CAAC;IAErB,qFAAqF;IACrF,YAAY,OAAO,EAAE,IAAI,CAAC,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"}
@@ -34,6 +34,15 @@ export declare namespace Passkey {
34
34
  readonly fields?: string;
35
35
  /** Text of the form's own button, in place of the method's. */
36
36
  readonly submit?: string;
37
+ /**
38
+ * Where the form confirms the person with a passkey they have, when
39
+ * its ceremony asks for a recent sign-in: the options endpoint, and the
40
+ * path the confirmation is sent to.
41
+ */
42
+ readonly confirm?: {
43
+ readonly endpoint: string;
44
+ readonly action: string;
45
+ };
37
46
  }
38
47
  /** The ceremony a signed form may start. */
39
48
  type Expected = {
@@ -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,EAA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DAA2D;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"}
@@ -69,6 +69,16 @@ export class Passkey {
69
69
  const browser = this.#auth.browser(true);
70
70
  const user = method === "register" ? crypto.randomUUID() : undefined;
71
71
  noStore(this.#c.res.headers);
72
+ /** A signed start of a ceremony this page may make */
73
+ const seal = (method, action) => Token.seal(this.#auth.options.secret, "passkey", JSON.stringify({
74
+ method,
75
+ action,
76
+ origin: this.#auth.options.origin,
77
+ browser,
78
+ expiration: Date.now() + Time.hour,
79
+ user: method === "register" ? user : undefined,
80
+ fields: options.fields,
81
+ }));
72
82
  const Form = Object.assign((props) => route.Form({
73
83
  ...props,
74
84
  children: [
@@ -88,16 +98,14 @@ export class Passkey {
88
98
  nonce: options.nonce,
89
99
  "data-passkey": method,
90
100
  "data-endpoint": options.endpoint,
91
- "data-bootstrap": await Token.seal(this.#auth.options.secret, "passkey", JSON.stringify({
92
- method,
93
- // the form's own params, checked by its props type
94
- action: route.url({ params: props.params }),
95
- origin: this.#auth.options.origin,
96
- browser,
97
- expiration: Date.now() + Time.hour,
98
- user,
99
- fields: options.fields,
100
- })),
101
+ "data-bootstrap": await seal(method,
102
+ // the form's own params, checked by its props type
103
+ route.url({ params: props.params })),
104
+ ...(options.confirm && {
105
+ "data-confirm": await seal("login", options.confirm.action),
106
+ "data-confirm-endpoint": options.confirm.endpoint,
107
+ "data-confirm-action": options.confirm.action,
108
+ }),
101
109
  }),
102
110
  jsx("noscript", {
103
111
  children: "JavaScript is required for authentication.",
@@ -25,6 +25,12 @@ export declare class State {
25
25
  browser(create?: boolean): string | undefined;
26
26
  /** Read a non-expired, non-revoked session, renewing it while it is used. */
27
27
  session(): Promise<ContextType.Session | null>;
28
+ /**
29
+ * @param within Milliseconds
30
+ * @returns `true` when the person signed in that recently, in this
31
+ * browser: what a session taken over later cannot say
32
+ */
33
+ recent(within: number): Promise<boolean>;
28
34
  /**
29
35
  * Return to a local path after the next login, such as an agent's
30
36
  * authorization request, or the page that sent the user to log in. Any
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/auth/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,IAAI,WAAW,EAAS,MAAM,qBAAqB,CAAC;AAEzE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,yBAAiB,KAAK,CAAC;IACtB,oFAAoF;IACpF,KAAY,OAAO,GAAG,IAAI,CACzB,IAAI,CAAC,OAAO,EACZ,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CACzC,GACA,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,UAAU,CAAC,CAAC;IAC1C,2EAA2E;IAC3E,KAAY,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,CAAC,CAAC;CACnE;AAED,yEAAyE;AACzE,qBAAa,KAAK;;IAQjB,+CAA+C;IAC/C,QAAQ,CAAC,OAAO;;;;;;;MAAC;IAEjB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,KAAK,CAAC,OA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;;OAIG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,oBAG1B;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,QAMpB;IAED;;;OAGG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,UAQtB;IA0BD,yEAAyE;IACnE,KAAK,CAAC,IAAI,EAAE,MAAM;;;;OAqBvB;IAED,kFAAkF;IAC5E,MAAM,kBAOX;CACD"}
@@ -92,8 +92,10 @@ export class State {
92
92
  if (session &&
93
93
  session.id === id &&
94
94
  session.expiration > now &&
95
- session.started + this.options.lifetime > now)
95
+ session.started + this.options.lifetime > now) {
96
+ this.#started = session.started;
96
97
  return this.#renew(session, now);
98
+ }
97
99
  this.#clear();
98
100
  return null;
99
101
  }
@@ -122,6 +124,17 @@ export class State {
122
124
  session() {
123
125
  return (this.#session ??= this.#read());
124
126
  }
127
+ /** When the browser's session signed in, once it is read */
128
+ #started;
129
+ /**
130
+ * @param within Milliseconds
131
+ * @returns `true` when the person signed in that recently, in this
132
+ * browser: what a session taken over later cannot say
133
+ */
134
+ async recent(within) {
135
+ await this.session();
136
+ return this.#started !== undefined && Date.now() - this.#started <= within;
137
+ }
125
138
  /**
126
139
  * Return to a local path after the next login, such as an agent's
127
140
  * authorization request, or the page that sent the user to log in. Any
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.20",
4
+ "version": "7.0.0-next.22",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,3 +1,3 @@
1
1
  // Generated by scripts/client.js; edit client.ts instead.
2
- export const source = "export function listen(e,t,n,r){let i=document.getElementById(e),a=i?.closest(`form`),o=i?.previousElementSibling,s=a?.querySelector(`[data-passkey-error]:not([data-passkey-fallback])`)??o;if(!(a instanceof HTMLFormElement)||!(s instanceof HTMLElement))return;s!==o&&o instanceof HTMLElement&&(o.hidden=!0);let c=e=>{let t=a.elements.namedItem(e);if(t instanceof HTMLInputElement)return t;let n=document.createElement(`input`);return n.type=`hidden`,n.name=e,a.append(n),n},l=c(`credential`),u=c(`ceremony`),d=!1,f=!1,p=!1,m,h=0,g,_=()=>`Too many requests. Try again in ${Math.ceil((h-Date.now())/1e3)} seconds.`,v=()=>{clearTimeout(g),g=void 0,d=f=p=!1,m=void 0,l.value=u.value=``,a.removeAttribute(`aria-busy`)},y=(e,t)=>{e instanceof HTMLElement&&`setCustomValidity`in e&&typeof e.setCustomValidity==`function`&&e.setCustomValidity(t)},b=e=>y(e.target,``);return a.addEventListener(`input`,b),a.addEventListener(`change`,b),a.addEventListener(`submit`,async e=>{if(!e.submitter?.hasAttribute(`formaction`)){if(f){p?m=e:e.preventDefault();return}if(e.preventDefault(),!d){if(h>Date.now()){s.textContent=_();return}d=!0,s.textContent=``,a.setAttribute(`aria-busy`,`true`);try{if(!window.PublicKeyCredential?.parseCreationOptionsFromJSON||!PublicKeyCredential.parseRequestOptionsFromJSON||!navigator.credentials)throw Error(`Passkeys are unavailable in this browser.`);let i=new FormData(a);i.delete(`credential`),i.delete(`ceremony`),i.set(`bootstrap`,t);let o=await fetch(n,{method:`POST`,body:i,credentials:`same-origin`,cache:`no-store`});if(o.status===429){let e=Date.now(),t=o.headers.get(`retry-after`)??`60`,n=/^\\d+$/.test(t)?e+Number(t)*1e3:Date.parse(t);throw h=Number.isNaN(n)?e+6e4:Math.min(e+36e5,Math.max(e+1e3,n)),Error(_())}if(o.status===422){let e=await o.json();if(e.fields&&typeof e.fields==`object`)for(let[t,n]of Object.entries(e.fields))typeof n==`string`&&y(a.elements.namedItem(t),n);throw a.reportValidity(),Error(`Check your registration details and try again.`)}if(o.status===410)throw Error(`This page has expired. Reload and try again.`);if(!o.ok)throw Error(`Could not start the passkey request. Try again.`);let c=await o.json();u.value=c.ceremony;let d=await(r===`register`?navigator.credentials.create({publicKey:PublicKeyCredential.parseCreationOptionsFromJSON(c.options)}):navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(c.options)}));if(!(d instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);l.value=JSON.stringify(d),f=!0,p=!0,m=void 0,HTMLFormElement.prototype.requestSubmit.call(a,e.submitter??void 0),p=!1,f=!!(m&&!m.defaultPrevented),f&&(g=setTimeout(()=>{v(),s.textContent=r===`register`?`If registration already completed, sign in; otherwise try again.`:`If sign-in did not finish, try again.`},12e4))}catch(e){v(),s.textContent=e instanceof DOMException&&e.name===`NotAllowedError`?`Passkey request canceled. Try again.`:e instanceof Error?e.message:`Could not complete the passkey request. Try again.`}finally{d=!1,p=!1,f||a.removeAttribute(`aria-busy`)}}}}),v}const t=new WeakMap,n=()=>document.querySelectorAll(`script[data-passkey]`),r=()=>{for(let r of n()){if(t.has(r))continue;let n=r.dataset.passkey;if(n===`register`||n===`login`){let i=listen(r.id,r.dataset.bootstrap??``,r.dataset.endpoint??``,n);i&&t.set(r,i)}}};typeof document<`u`&&(window.addEventListener(`pageshow`,e=>{if(e.persisted)for(let e of n())t.get(e)?.()}),r(),new MutationObserver(r).observe(document.documentElement,{childList:!0,subtree:!0}));";
3
- export const etag = "W/\"db299e39015256815ea2f2eec92a5cddf0ff95a21a5fcf8bc664bef0fd6ff6dc\"";
2
+ export const source = "export function listen(e,t,n,r,i){let a=document.getElementById(e),o=a?.closest(`form`),s=a?.previousElementSibling,c=o?.querySelector(`[data-passkey-error]:not([data-passkey-fallback])`)??s;if(!(o instanceof HTMLFormElement)||!(c instanceof HTMLElement))return;c!==s&&s instanceof HTMLElement&&(s.hidden=!0);let l=e=>{let t=o.elements.namedItem(e);if(t instanceof HTMLInputElement)return t;let n=document.createElement(`input`);return n.type=`hidden`,n.name=e,o.append(n),n},u=l(`credential`),d=l(`ceremony`),f=!1,p=!1,m=!1,h,g=0,_,v=()=>`Too many requests. Try again in ${Math.ceil((g-Date.now())/1e3)} seconds.`,y=()=>{clearTimeout(_),_=void 0,f=p=m=!1,h=void 0,u.value=d.value=``,o.removeAttribute(`aria-busy`)},b=(e,t)=>{e instanceof HTMLElement&&`setCustomValidity`in e&&typeof e.setCustomValidity==`function`&&e.setCustomValidity(t)},x=e=>b(e.target,``);return o.addEventListener(`input`,x),o.addEventListener(`change`,x),o.addEventListener(`submit`,async e=>{if(!e.submitter?.hasAttribute(`formaction`)){if(p){m?h=e:e.preventDefault();return}if(e.preventDefault(),!f){if(g>Date.now()){c.textContent=v();return}f=!0,c.textContent=``,o.setAttribute(`aria-busy`,`true`);try{if(!window.PublicKeyCredential?.parseCreationOptionsFromJSON||!PublicKeyCredential.parseRequestOptionsFromJSON||!navigator.credentials)throw Error(`Passkeys are unavailable in this browser.`);let a=new FormData(o);a.delete(`credential`),a.delete(`ceremony`),a.set(`bootstrap`,t);let s=await fetch(n,{method:`POST`,body:a,credentials:`same-origin`,cache:`no-store`});if(s.status===429){let e=Date.now(),t=s.headers.get(`retry-after`)??`60`,n=/^\\d+$/.test(t)?e+Number(t)*1e3:Date.parse(t);throw g=Number.isNaN(n)?e+6e4:Math.min(e+36e5,Math.max(e+1e3,n)),Error(v())}if(s.status===422){let e=await s.json();if(e.fields&&typeof e.fields==`object`)for(let[t,n]of Object.entries(e.fields))typeof n==`string`&&b(o.elements.namedItem(t),n);throw o.reportValidity(),Error(`Check your registration details and try again.`)}if(s.status===410)throw Error(`This page has expired. Reload and try again.`);if(s.status===401){if(!i)throw Error(`Sign in again, then try once more.`);let e=(e,t)=>fetch(e,{method:`POST`,body:t,credentials:`same-origin`,cache:`no-store`,redirect:`manual`}),t=new FormData;t.set(`bootstrap`,i.bootstrap);let n=await e(i.endpoint,t);if(n.status===410)throw Error(`This page has expired. Reload and try again.`);if(!n.ok)throw Error(`Sign in again, then try once more.`);let r=await n.json(),a=await navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(r.options)});if(!(a instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);let o=new FormData;throw o.set(`credential`,JSON.stringify(a)),o.set(`ceremony`,r.ceremony),(await e(i.action,o)).status===204?Error(`Confirmed. Press the button again to finish.`):Error(`Could not confirm your passkey. Try again.`)}if(!s.ok)throw Error(`Could not start the passkey request. Try again.`);let l=await s.json();d.value=l.ceremony;let f=await(r===`register`?navigator.credentials.create({publicKey:PublicKeyCredential.parseCreationOptionsFromJSON(l.options)}):navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(l.options)}));if(!(f instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);u.value=JSON.stringify(f),p=!0,m=!0,h=void 0,HTMLFormElement.prototype.requestSubmit.call(o,e.submitter??void 0),m=!1,p=!!(h&&!h.defaultPrevented),p&&(_=setTimeout(()=>{y(),c.textContent=r===`register`?`If registration already completed, sign in; otherwise try again.`:`If sign-in did not finish, try again.`},12e4))}catch(e){y(),c.textContent=e instanceof DOMException&&e.name===`NotAllowedError`?`Passkey request canceled. Try again.`:e instanceof Error?e.message:`Could not complete the passkey request. Try again.`}finally{f=!1,m=!1,p||o.removeAttribute(`aria-busy`)}}}}),y}const t=new WeakMap,n=()=>document.querySelectorAll(`script[data-passkey]`),r=()=>{for(let r of n()){if(t.has(r))continue;let n=r.dataset.passkey;if(n===`register`||n===`login`){let i=listen(r.id,r.dataset.bootstrap??``,r.dataset.endpoint??``,n,r.dataset.confirm?{bootstrap:r.dataset.confirm,endpoint:r.dataset.confirmEndpoint??``,action:r.dataset.confirmAction??``}:void 0);i&&t.set(r,i)}}};typeof document<`u`&&(window.addEventListener(`pageshow`,e=>{if(e.persisted)for(let e of n())t.get(e)?.()}),r(),new MutationObserver(r).observe(document.documentElement,{childList:!0,subtree:!0}));";
3
+ export const etag = "W/\"cd84978ac63729e95e76d936a954d6e7d110f47e0b70102a09b9e990f022a9c5\"";
@@ -4,6 +4,8 @@ export function listen(
4
4
  bootstrap: string,
5
5
  endpoint: string,
6
6
  method: "register" | "login",
7
+ /** Confirms the person with a passkey they have, when the form asks */
8
+ confirm?: { bootstrap: string; endpoint: string; action: string },
7
9
  ) {
8
10
  const script = document.getElementById(id);
9
11
  const form = script?.closest("form");
@@ -114,6 +116,41 @@ export function listen(
114
116
  }
115
117
  if (res.status === 410)
116
118
  throw new Error("This page has expired. Reload and try again.");
119
+ // adding a passkey asks for a recent sign-in, or for a passkey the
120
+ // person already has
121
+ if (res.status === 401) {
122
+ if (!confirm) throw new Error("Sign in again, then try once more.");
123
+ const send = (url: string, body: FormData) =>
124
+ fetch(url, {
125
+ method: "POST",
126
+ body,
127
+ credentials: "same-origin",
128
+ cache: "no-store",
129
+ redirect: "manual",
130
+ });
131
+ const ask = new FormData();
132
+ ask.set("bootstrap", confirm.bootstrap);
133
+ const asked = await send(confirm.endpoint, ask);
134
+ if (asked.status === 410)
135
+ throw new Error("This page has expired. Reload and try again.");
136
+ if (!asked.ok) throw new Error("Sign in again, then try once more.");
137
+ const proof: { ceremony: string; options: unknown } =
138
+ await asked.json();
139
+ const mine = await navigator.credentials.get({
140
+ publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(
141
+ proof.options as PublicKeyCredentialRequestOptionsJSON,
142
+ ),
143
+ });
144
+ if (!(mine instanceof PublicKeyCredential))
145
+ throw new Error("No passkey was returned. Try again.");
146
+ const answer = new FormData();
147
+ answer.set("credential", JSON.stringify(mine));
148
+ answer.set("ceremony", proof.ceremony);
149
+ if ((await send(confirm.action, answer)).status !== 204)
150
+ throw new Error("Could not confirm your passkey. Try again.");
151
+ // a browser asks for a new press before its next passkey prompt
152
+ throw new Error("Confirmed. Press the button again to finish.");
153
+ }
117
154
  if (!res.ok)
118
155
  throw new Error("Could not start the passkey request. Try again.");
119
156
 
@@ -188,6 +225,13 @@ const scan = () => {
188
225
  script.dataset.bootstrap ?? "",
189
226
  script.dataset.endpoint ?? "",
190
227
  method,
228
+ script.dataset.confirm
229
+ ? {
230
+ bootstrap: script.dataset.confirm,
231
+ endpoint: script.dataset.confirmEndpoint ?? "",
232
+ action: script.dataset.confirmAction ?? "",
233
+ }
234
+ : undefined,
191
235
  );
192
236
  if (reset) attached.set(script, reset);
193
237
  }
@@ -54,6 +54,7 @@ export function configure<U extends Auth.Users>(
54
54
  login: "/auth/login",
55
55
  logout: "/auth/logout",
56
56
  passkey: "/auth/passkey",
57
+ confirm: "/auth/confirm",
57
58
  link: "/auth/link",
58
59
  options: "/_passkey/options",
59
60
  } as const;
@@ -303,7 +304,11 @@ export function configure<U extends Auth.Users>(
303
304
  const input = await Issue.data(c);
304
305
  if (!input || input.issues) throw new Issue("passkey request");
305
306
  const session = await state(c).session();
306
- if (!session) return c.text("Sign in to add a passkey.", 401);
307
+ // a passkey outlasts the session that adds it, so only a person
308
+ // who has just signed in adds one, not whoever holds an old session.
309
+ // The form then confirms them with a passkey they have.
310
+ if (!session || !(await state(c).recent(10 * Time.minute)))
311
+ return c.text("Confirm your passkey to add another.", 401);
307
312
  const [[account], exclude] = await Promise.all([
308
313
  options.database
309
314
  .sql`SELECT * FROM ${users} WHERE ${users.columns.id!} = ${session.user}`,
@@ -317,6 +322,39 @@ export function configure<U extends Auth.Users>(
317
322
  exclude,
318
323
  });
319
324
  });
325
+ // Confirms the person signed in with a passkey of theirs, which starts
326
+ // their session again: what adding a passkey asks for after a while
327
+ const confirming = Route.post(`${paths.options}/confirm`)
328
+ .fields({ bootstrap: Field.hidden() })
329
+ .use(guard("login", true), async (c) => {
330
+ const input = await Issue.data(c);
331
+ if (!input || input.issues) throw new Issue("confirm request");
332
+ const session = await state(c).session();
333
+ if (!session) return c.text("Sign in to add a passkey.", 401);
334
+ await Passkey.issue(c, state(c), input.data.bootstrap, {
335
+ method: "login",
336
+ action: paths.confirm,
337
+ // only their own, so the picker offers no other account's
338
+ allow: await storage.credentials.list(session.user),
339
+ });
340
+ });
341
+ const confirm = Route.post(paths.confirm)
342
+ .fields(Passkey.shape)
343
+ .use(guard("login"), async (c) => {
344
+ if (!(await Issue.data(c))) throw new Issue("confirm request");
345
+ const session = await state(c).session();
346
+ if (!session) throw new Issue("session");
347
+ const credential = await new Passkey(c, state(c)).login(
348
+ storage.credentials,
349
+ undefined,
350
+ session.user,
351
+ );
352
+ if (credential.user !== session.user) throw new Issue("user");
353
+ // a session that starts now, in place of the old one
354
+ await state(c).login(session.user);
355
+ c.res.status = 204;
356
+ c.res.body = null;
357
+ });
320
358
  /** The parameter of the authentication page a link's token is in */
321
359
  const linked = "_link";
322
360
  const link = Route.post(paths.link)
@@ -335,6 +373,8 @@ export function configure<U extends Auth.Users>(
335
373
  logout,
336
374
  add,
337
375
  link,
376
+ confirm,
377
+ confirming,
338
378
  registration,
339
379
  assertion,
340
380
  adding,
@@ -410,6 +450,7 @@ export function configure<U extends Auth.Users>(
410
450
  ...props,
411
451
  endpoint: adding.url(),
412
452
  submit: "Add passkey",
453
+ confirm: { endpoint: confirming.url(), action: paths.confirm },
413
454
  });
414
455
  Register.Issue = error("register", Register.Issue);
415
456
  Login.Issue = error("login", Login.Issue);
package/src/auth/index.ts CHANGED
@@ -117,8 +117,13 @@ export namespace Auth {
117
117
  | "/auth/register"
118
118
  | "/auth/login"
119
119
  | "/auth/logout"
120
+ | "/auth/passkey"
121
+ | "/auth/link"
122
+ | "/auth/confirm"
120
123
  | "/_passkey/options/register"
121
124
  | "/_passkey/options/login"
125
+ | "/_passkey/options/add"
126
+ | "/_passkey/options/confirm"
122
127
  | "/_passkey/client.js";
123
128
 
124
129
  /**
@@ -46,6 +46,12 @@ export namespace Passkey {
46
46
  readonly fields?: string;
47
47
  /** Text of the form's own button, in place of the method's. */
48
48
  readonly submit?: string;
49
+ /**
50
+ * Where the form confirms the person with a passkey they have, when
51
+ * its ceremony asks for a recent sign-in: the options endpoint, and the
52
+ * path the confirmation is sent to.
53
+ */
54
+ readonly confirm?: { readonly endpoint: string; readonly action: string };
49
55
  }
50
56
  /** The ceremony a signed form may start. */
51
57
  export type Expected = {
@@ -136,6 +142,21 @@ export class Passkey {
136
142
  const browser = this.#auth.browser(true);
137
143
  const user = method === "register" ? crypto.randomUUID() : undefined;
138
144
  noStore(this.#c.res.headers);
145
+ /** A signed start of a ceremony this page may make */
146
+ const seal = (method: "register" | "login", action: string) =>
147
+ Token.seal(
148
+ this.#auth.options.secret,
149
+ "passkey",
150
+ JSON.stringify({
151
+ method,
152
+ action,
153
+ origin: this.#auth.options.origin,
154
+ browser,
155
+ expiration: Date.now() + Time.hour,
156
+ user: method === "register" ? user : undefined,
157
+ fields: options.fields,
158
+ }),
159
+ );
139
160
  const Form: Passkey.Component<Pattern> = Object.assign(
140
161
  (props: Parameters<Route.Form<Pattern>>[0]) =>
141
162
  route.Form({
@@ -159,20 +180,16 @@ export class Passkey {
159
180
  nonce: options.nonce,
160
181
  "data-passkey": method,
161
182
  "data-endpoint": options.endpoint,
162
- "data-bootstrap": await Token.seal(
163
- this.#auth.options.secret,
164
- "passkey",
165
- JSON.stringify({
166
- method,
167
- // the form's own params, checked by its props type
168
- action: route.url({ params: props.params } as never),
169
- origin: this.#auth.options.origin,
170
- browser,
171
- expiration: Date.now() + Time.hour,
172
- user,
173
- fields: options.fields,
174
- }),
183
+ "data-bootstrap": await seal(
184
+ method,
185
+ // the form's own params, checked by its props type
186
+ route.url({ params: props.params } as never),
175
187
  ),
188
+ ...(options.confirm && {
189
+ "data-confirm": await seal("login", options.confirm.action),
190
+ "data-confirm-endpoint": options.confirm.endpoint,
191
+ "data-confirm-action": options.confirm.action,
192
+ }),
176
193
  }),
177
194
  jsx("noscript", {
178
195
  children: "JavaScript is required for authentication.",
package/src/auth/state.ts CHANGED
@@ -113,8 +113,10 @@ export class State {
113
113
  session.id === id &&
114
114
  session.expiration > now &&
115
115
  session.started + this.options.lifetime > now
116
- )
116
+ ) {
117
+ this.#started = session.started;
117
118
  return this.#renew(session, now);
119
+ }
118
120
  this.#clear();
119
121
  return null;
120
122
  }
@@ -146,6 +148,19 @@ export class State {
146
148
  return (this.#session ??= this.#read());
147
149
  }
148
150
 
151
+ /** When the browser's session signed in, once it is read */
152
+ #started: number | undefined;
153
+
154
+ /**
155
+ * @param within Milliseconds
156
+ * @returns `true` when the person signed in that recently, in this
157
+ * browser: what a session taken over later cannot say
158
+ */
159
+ async recent(within: number) {
160
+ await this.session();
161
+ return this.#started !== undefined && Date.now() - this.#started <= within;
162
+ }
163
+
149
164
  /**
150
165
  * Return to a local path after the next login, such as an agent's
151
166
  * authorization request, or the page that sent the user to log in. Any