ovr 7.0.0-next.21 → 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 +6 -0
- package/dist/auth/client-source.d.ts +2 -2
- package/dist/auth/client-source.d.ts.map +1 -1
- package/dist/auth/client-source.js +2 -2
- package/dist/auth/client.d.ts +7 -1
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +43 -5
- package/dist/auth/configure.d.ts +5 -0
- package/dist/auth/configure.d.ts.map +1 -1
- package/dist/auth/configure.js +41 -2
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/passkey.d.ts +9 -0
- package/dist/auth/passkey.d.ts.map +1 -1
- package/dist/auth/passkey.js +18 -10
- package/package.json +1 -1
- package/src/auth/client-source.ts +2 -2
- package/src/auth/client.ts +44 -3
- package/src/auth/configure.ts +40 -2
- package/src/auth/index.ts +5 -0
- package/src/auth/passkey.ts +30 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 7.0.0-next.21
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const source = "export function listen(e,t,n,r){let
|
|
2
|
-
export declare const etag = "W/\"
|
|
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,
|
|
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
|
|
3
|
-
export const etag = "W/\"
|
|
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\"";
|
package/dist/auth/client.d.ts
CHANGED
|
@@ -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"
|
|
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,
|
|
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"}
|
package/dist/auth/client.js
CHANGED
|
@@ -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,9 +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.");
|
|
109
|
-
// adding a passkey asks for a recent sign-in
|
|
110
|
-
|
|
111
|
-
|
|
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
|
+
}
|
|
112
144
|
if (!res.ok)
|
|
113
145
|
throw new Error("Could not start the passkey request. Try again.");
|
|
114
146
|
// creation options for a registration, request options for a login
|
|
@@ -169,7 +201,13 @@ const scan = () => {
|
|
|
169
201
|
continue;
|
|
170
202
|
const method = script.dataset.passkey;
|
|
171
203
|
if (method === "register" || method === "login") {
|
|
172
|
-
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);
|
|
173
211
|
if (reset)
|
|
174
212
|
attached.set(script, reset);
|
|
175
213
|
}
|
package/dist/auth/configure.d.ts
CHANGED
|
@@ -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
|
|
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"}
|
package/dist/auth/configure.js
CHANGED
|
@@ -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
|
};
|
|
@@ -259,9 +260,10 @@ export function configure(options, storage, state) {
|
|
|
259
260
|
throw new Issue("passkey request");
|
|
260
261
|
const session = await state(c).session();
|
|
261
262
|
// a passkey outlasts the session that adds it, so only a person
|
|
262
|
-
// who has just signed in adds one, not whoever holds an old session
|
|
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.
|
|
263
265
|
if (!session || !(await state(c).recent(10 * Time.minute)))
|
|
264
|
-
return c.text("
|
|
266
|
+
return c.text("Confirm your passkey to add another.", 401);
|
|
265
267
|
const [[account], exclude] = await Promise.all([
|
|
266
268
|
options.database
|
|
267
269
|
.sql `SELECT * FROM ${users} WHERE ${users.columns.id} = ${session.user}`,
|
|
@@ -275,6 +277,40 @@ export function configure(options, storage, state) {
|
|
|
275
277
|
exclude,
|
|
276
278
|
});
|
|
277
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
|
+
});
|
|
278
314
|
/** The parameter of the authentication page a link's token is in */
|
|
279
315
|
const linked = "_link";
|
|
280
316
|
const link = Route.post(paths.link)
|
|
@@ -295,6 +331,8 @@ export function configure(options, storage, state) {
|
|
|
295
331
|
logout,
|
|
296
332
|
add,
|
|
297
333
|
link,
|
|
334
|
+
confirm,
|
|
335
|
+
confirming,
|
|
298
336
|
registration,
|
|
299
337
|
assertion,
|
|
300
338
|
adding,
|
|
@@ -359,6 +397,7 @@ export function configure(options, storage, state) {
|
|
|
359
397
|
...props,
|
|
360
398
|
endpoint: adding.url(),
|
|
361
399
|
submit: "Add passkey",
|
|
400
|
+
confirm: { endpoint: confirming.url(), action: paths.confirm },
|
|
362
401
|
});
|
|
363
402
|
Register.Issue = error("register", Register.Issue);
|
|
364
403
|
Login.Issue = error("login", Login.Issue);
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -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
|
*
|
package/dist/auth/index.d.ts.map
CHANGED
|
@@ -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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3E,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"}
|
package/dist/auth/passkey.d.ts
CHANGED
|
@@ -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,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,iBAAiB,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;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"}
|
package/dist/auth/passkey.js
CHANGED
|
@@ -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
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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.",
|
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.
|
|
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
|
|
3
|
-
export const etag = "W/\"
|
|
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\"";
|
package/src/auth/client.ts
CHANGED
|
@@ -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,9 +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.");
|
|
117
|
-
// adding a passkey asks for a recent sign-in
|
|
118
|
-
|
|
119
|
-
|
|
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
|
+
}
|
|
120
154
|
if (!res.ok)
|
|
121
155
|
throw new Error("Could not start the passkey request. Try again.");
|
|
122
156
|
|
|
@@ -191,6 +225,13 @@ const scan = () => {
|
|
|
191
225
|
script.dataset.bootstrap ?? "",
|
|
192
226
|
script.dataset.endpoint ?? "",
|
|
193
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,
|
|
194
235
|
);
|
|
195
236
|
if (reset) attached.set(script, reset);
|
|
196
237
|
}
|
package/src/auth/configure.ts
CHANGED
|
@@ -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;
|
|
@@ -304,9 +305,10 @@ export function configure<U extends Auth.Users>(
|
|
|
304
305
|
if (!input || input.issues) throw new Issue("passkey request");
|
|
305
306
|
const session = await state(c).session();
|
|
306
307
|
// a passkey outlasts the session that adds it, so only a person
|
|
307
|
-
// who has just signed in adds one, not whoever holds an old session
|
|
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.
|
|
308
310
|
if (!session || !(await state(c).recent(10 * Time.minute)))
|
|
309
|
-
return c.text("
|
|
311
|
+
return c.text("Confirm your passkey to add another.", 401);
|
|
310
312
|
const [[account], exclude] = await Promise.all([
|
|
311
313
|
options.database
|
|
312
314
|
.sql`SELECT * FROM ${users} WHERE ${users.columns.id!} = ${session.user}`,
|
|
@@ -320,6 +322,39 @@ export function configure<U extends Auth.Users>(
|
|
|
320
322
|
exclude,
|
|
321
323
|
});
|
|
322
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
|
+
});
|
|
323
358
|
/** The parameter of the authentication page a link's token is in */
|
|
324
359
|
const linked = "_link";
|
|
325
360
|
const link = Route.post(paths.link)
|
|
@@ -338,6 +373,8 @@ export function configure<U extends Auth.Users>(
|
|
|
338
373
|
logout,
|
|
339
374
|
add,
|
|
340
375
|
link,
|
|
376
|
+
confirm,
|
|
377
|
+
confirming,
|
|
341
378
|
registration,
|
|
342
379
|
assertion,
|
|
343
380
|
adding,
|
|
@@ -413,6 +450,7 @@ export function configure<U extends Auth.Users>(
|
|
|
413
450
|
...props,
|
|
414
451
|
endpoint: adding.url(),
|
|
415
452
|
submit: "Add passkey",
|
|
453
|
+
confirm: { endpoint: confirming.url(), action: paths.confirm },
|
|
416
454
|
});
|
|
417
455
|
Register.Issue = error("register", Register.Issue);
|
|
418
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
|
/**
|
package/src/auth/passkey.ts
CHANGED
|
@@ -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
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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.",
|